在SpriteKit中检测对象的子节点上的触摸

Kyl*_*lan 11 xcode touch ios sprite-kit swift

我有一个自定义类,它是一个SKNode,其中包含几个SKSpriteNodes.有没有办法可以从我的游戏场景中检测这些孩子SKSpriteNodes的触摸?

我在迅速工作

mei*_*man 10

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {

   let touch = touches.anyObject() as UITouch

   let touchLocation = touch.locationInNode(self)

    if([yourSprite containsPoint: touchLocation])
    {
         //sprite contains touch
    }
}
Run Code Online (Sandbox Code Playgroud)

资料来源:http://www.raywenderlich.com/84434/sprite-kit-swift-tutorial-beginners