Enabled设置为YES的Sprite被普通Sprite覆盖时

Enabled设置为YES的Sprite被普通Sprite覆盖时

本文介绍了当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似乎仍然能够接收到触摸但将其丢弃.

I feel something is unclear here because it seems still that sprite B receives the touch but throws it away.

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

是否要解决此问题?只要某人的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覆盖时,不会接收触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:58