本文介绍了检测SpriteKit中对象子节点的触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义类,它是一个 SKNode,其中又包含几个 SKSpriteNode.有没有办法从我的游戏场景中检测到对这些子 SKSpriteNode 的触摸?
I have a custom class that is an SKNode, which in turn has several SKSpriteNodes in it. Is there a way I can detect touches on these child SKSpriteNodes from my game scene?
我正在快速工作
推荐答案
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
这篇关于检测SpriteKit中对象子节点的触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!