是否可以在项目中的多个位置或对象中使用 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!")
}
}
目前我有类似的东西,但没有触发 touchesBegan,这是不正确的做法吗?
最佳答案
是的,在多个地方实现 touchesBegan
应该是完全没问题的。关于为什么不叫他们,也许这会有所帮助? Custom SKSpriteNode not detected during touch
关于ios - 在多个类中添加 touchesBegan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27218627/