我有一个类,我想封装所有的触摸周围的逻辑。但是,我也想将触摸事件传递到GameScene
,以便我可以删除其他节点。我认为super.touchesBegan(touches, withEvent: event)
会工作,但没有骰子。Swift SKSpriteNode类不注册触摸到GameScene
我也尝试了Delegate
模式,但我无法让它工作,也不太喜欢这种方法。
import Foundation
import SpriteKit
class LevelSelect: SKSpriteNode {
var level:Int = 0
init(x: CGFloat, y: CGFloat) {
// init code ...
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
// logic affecting this class
super.touchesBegan(touches, withEvent: event)
}
}
您是否试图让节点在触摸时做某些事情,或者您在定位手指位置时遇到问题? – sicvayne