如果我触摸除按钮之外的游戏崩溃。我能做什么?如何?我想忽略除按钮之外的所有触摸。我怎样才能做到这一点? 这里是我的touchesBegan:斯威夫特3我的代码游戏无法正常工作
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
if let location = touch?.location(in: self),
let node = self.nodes(at: location).first {
var player = SKSpriteNode()
if node.name == "BlueButton" {
player = playerB
playerB.isHidden = false
} else if node.name == "RedButton" {
player = playerR
playerR.isHidden = false
} else if node.name == "YellowButton" {
player = playerY
playerY.isHidden = false
} else if node.name == "GreenButton" {
player = playerG
playerG.isHidden = false
}
for sprite in [playerB, playerW, playerR, playerY, playerG] {
sprite?.removeFromParent()
}
player.position = CGPoint(x: 0, y: -60)
addChild(player)
}
}
这里是我的touchesEnded功能
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
addChild(playerW)
playerB.removeFromParent()
playerR.removeFromParent()
playerY.removeFromParent()
playerG.removeFromParent()
}
我明白你的英语。我还注意到你的final * else *是* gameOver()*。尽管**没有**调试你的代码(道歉)我的问题是这样的:它总是打这个不管是什么?更重要的问题是,你能否给我一些我可以验证和重现的东西?你有没有做过任何与断点首次亮相? – dfd
因此,第一次如果我按下右按钮,它的工作,但比每次打印游戏结束... –
而且我没有任何断点。它只是不正常工作 –