且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-01 20:00:26

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
    }
}

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