如何禁用SpriteKit节点触摸事件,然后在25秒后启用它,以便当触摸节点时,将将用户带到下一个场景?
我正在设置一个播放音频文件25秒钟的游戏序列,然后我希望用户能够单击将用户进入下一个场景的SpriteKit节点。问题是节点不能隐藏。它需要可见,但可以禁用,然后在25秒后可见并启用触摸。
if nextButton.contains(location) {
if nextButton.isHidden == true {
nextButton.isUserInteractionEnabled = false
} else {
goToScene(scene: getNextScene()!)
}
我已经使用了此代码,用于何时隐藏了SpriteKit节点,但是这次必须在整个时间内可见。
从外观上看,您的GamesScene是处理触摸事件的方法,因此,当您播放音频时,您应该做这样的事情:
self.userInteractionEnabled = false
let audio = SKAudioNode()
audio.run{
SKAction.group([SKAction.play,
SKAction.sequence([
SKAction.wait(forDuration:25),
SKAction.run({self.userInteractionEnabled = true})
])
)
}
self.addChild(audio)
如果您使用的是弹奏动作
self.userInteractionEnabled = false
let audio = SKSpriteNode()
audio.run{
SKAction.sequence([
SKAction.playSoundFileNamed("mySound",true),
SKAction.run({self.userInteractionEnabled = true})
])
}
基本上,这是设定延迟操作以在声音完成后启用触摸。