如果我觸摸除按鈕之外的遊戲崩潰。我能做什麼?如何?我想忽略除按鈕之外的所有觸摸。我怎樣才能做到這一點? 這裏是我的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
因此,第一次如果我按下右按鈕,它的工作,但比每次打印遊戲結束... –
而且我沒有任何斷點。它只是不正常工作 –