当userInteractionEnabled设置为YES的Sprite被普通Sprite覆盖时,不会接收触摸 [英] Sprite with userInteractionEnabled set to YES does not receive touches when covered by normal sprites

查看:104
本文介绍了当userInteractionEnabled设置为YES的Sprite被普通Sprite覆盖时,不会接收触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我放置了一个精灵A(子类可接收点击(userInteractionEnabled为YES)),然后放置一个普通的精灵B,该精灵B不在其之上(UserInteractionEnabled默认为否),完全覆盖了精灵A.

I put a sprite A (subclassed to receive hits (userInteractionEnabled to YES)), and then a normal sprite B that does not take hits on top of that (userInteractionEnabled default NO), completely covering sprite A.

点击小精灵B,我认为小精灵A会得到触摸,但是什么也没发生.文档中有关此问题的部分如下.

Tapping on sprite B, I assume that sprite A would get the touch but nothing happens. The part from docs about the matter is below.

我觉得这里还不清楚,因为精灵B似乎仍然能够接收到触摸但将其丢弃. 或,由于spriteA不可见,因此将其从可能的触摸接收器中删除.

I feel something is unclear here because it seems still that sprite B receives the touch but throws it away. OR, spriteA is removed from possible touch receiver because it's not visible.

从文档中: https: //developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Nodes/Nodes.html#//apple_ref/doc/uid/TP40013043-CH3-SW7

对于在命中测试期间要考虑的节点,其 userInteractionEnabled属性必须设置为YES.默认值 对于除场景节点以外的任何节点为NO.一个想要接收的节点 事件需要从事件中实施适当的响应者方法 父类(iOS上的UIResponder和OS X上的NSResponder).这是一 在以下几个必须实现平台特定代码的地方 雪碧套件

For a node to be considered during hit-testing, its userInteractionEnabled property must be set to YES. The default value is NO for any node except a scene node. A node that wants to receive events needs to implement the appropriate responder methods from its parent class (UIResponder on iOS and NSResponder on OS X). This is one of the few places where you must implement platform-specific code in Sprite Kit

是否要解决此问题? 只要某人的userInteractionEnabled为NO,它就不会干扰其他触摸接收器.

Anyway to fix this? As long as something's userInteractionEnabled is NO, it shouldn't interfere with other touch receivers.

更新:即使将子图形B的alpha设置为0.2,使子图形A变得非常明显,也不会使子图形A可以触摸.尽管未启用互动功能,但Sprite B完全吞噬"了触摸.

Update: Even setting sprite B's alpha to 0.2, making sprite A very visible, will not make sprite A touchable. Sprite B just totally "swallows" the touch, despite being not enabled for interaction.

推荐答案

这是我的解决方案,直到Apple以正确的行为更新SpriteKit或有人想出自己想要的方式使用它为止.

Here is my solution until Apple updates SpriteKit with correct behaviour, or someone acctually figures out how to use it like we want.

https://gist.github.com/bobmoff/7110052

将文件添加到您的项目中,并将其导入到Prefix标头中.现在,触摸应该可以按预期的方式进行.

Add the file to your project and import it in your Prefix header. Now touches should work the way intended.

这篇关于当userInteractionEnabled设置为YES的Sprite被普通Sprite覆盖时,不会接收触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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