私は、その周りのすべてのロジックをカプセル化したいクラスを持っています。しかし、タッチイベントを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