是否可以在项目的多个位置或对象中使用touchesBegan方法?
例如,如果我有一个带有两个按钮的主类:
class GameScene: SKScene, SKPhysicsContactDelegate {
let moveButton = MoveButton()
let fireButton = FireButton()
//add buttons to scene etc...
}
class MoveButton: SKSpriteNode {
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
NSLog("moved!")
}
}
class FireButton: SKSpriteNode {
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
NSLog("fired!")
}
}
目前我有类似的东西,但触摸开始没被击中,这是不正确的吗?
答案 0 :(得分:1)
是的,在几个地方实施touchesBegan
应该完全没问题。关于他们为什么不被召唤,或许这可以帮助? Custom SKSpriteNode not detected during touch