我有场景中一个按钮的代码,但我尝试使用相同的代码在同一场景中制作另一个按钮,但没有成功。这是我到目前为止的代码:
for touch:AnyObject in touches {
let location = touch.locationInNode(self)
if playGameButton.containsPoint(location) {
let newScene = GameplayScene(size: self.size)
newScene.scaleMode = scaleMode
self.view?.presentScene(newScene)
}
}
同样,这只是一个 按钮。当我对另一个图像使用相同的代码时,它不起作用。
最佳答案
解决此问题的更好方法是使用 SKSpriteNode 对象作为按钮并设置其名称属性以轻松区分多个按钮。例如,如果您有一个 SKSpriteNode 对象 button1:
button1.name = "first"
然后在你的 touch 方法中检查哪个被触摸,你可以使用 name 属性:
SKNode node = self.nodeAtPoint(location)
if node.name == "first" {
// do something
}
关于swift - 如何在 Swift 中制作充当按钮的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33621055/