游戏结束后尝试移除我的重启按钮
Trying to remove my restart button once it is game over
我试图在玩家失去 5 条生命后摆脱重启按钮,这是我创建的 GAMEOVER。这段代码不适合我,谁能帮我理解为什么?
func loseALife(){
if lives == 0 {
enumerateChildNodes(withName: "Restart", using: ({
(node, error) in
self.removeAllActions()
})
runGameOver()
}
}
这是重启按钮的功能
func createButton() {
restartButton = SKSpriteNode(imageNamed: "restart")
restartButton.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2)
restartButton.zPosition = 6
restartButton.setScale(0.5)
restartButton.name = "Restart"
self.addChild(restartButton)
而不是 self.removeAllActions()
使用
node.removeFromParent()
您使用的 self
在本例中指的是 GameScene,removeAllActions
仅适用于当前具有操作 运行 的游戏元素。变量 node
来自 enumerateChildNodes
的每次迭代,是对按钮的直接引用。
我试图在玩家失去 5 条生命后摆脱重启按钮,这是我创建的 GAMEOVER。这段代码不适合我,谁能帮我理解为什么?
func loseALife(){
if lives == 0 {
enumerateChildNodes(withName: "Restart", using: ({
(node, error) in
self.removeAllActions()
})
runGameOver()
}
}
这是重启按钮的功能
func createButton() {
restartButton = SKSpriteNode(imageNamed: "restart")
restartButton.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2)
restartButton.zPosition = 6
restartButton.setScale(0.5)
restartButton.name = "Restart"
self.addChild(restartButton)
而不是 self.removeAllActions()
使用
node.removeFromParent()
您使用的 self
在本例中指的是 GameScene,removeAllActions
仅适用于当前具有操作 运行 的游戏元素。变量 node
来自 enumerateChildNodes
的每次迭代,是对按钮的直接引用。