在SpriteKit中检测对象的子节点上的触摸 [英] Detect touch on child node of object in SpriteKit

查看:223
本文介绍了在SpriteKit中检测对象的子节点上的触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

我在swift工作

推荐答案

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中检测对象的子节点上的触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆