我创造了一个类似Flappy Bird的游戏.我已经设置了一个函数,以便在英雄死亡时调用restartScene.触摸时,这将重新启动游戏,以便用户可以继续玩游戏.
我的问题是,是否有可能在用户点击重启之前延迟2-3秒?
func restartScene(){
self.removeAllChildren()
self.removeAllActions()
died = false
gameStarted = false
score = 0
createScene()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if gameStarted == false{
gameStarted = true
for touch in touches{
let location = touch.location(in: self)
if died == true{
restartScene()
}
}
}
Run Code Online (Sandbox Code Playgroud)