gpt4 book ai didi

objective-c - userInteractionEnabled 设置为 YES 的 Sprite 在被普通 Sprite 覆盖时不会接收到触摸

转载 作者:太空狗 更新时间:2023-10-30 03:31:20 24 4
gpt4 key购买 nike

我放了一个 sprite A(被子类化以接收命中(userInteractionEnabled 为 YES)),然后是一个普通的 sprite B,它不接受命中(userInteractionEnabled 默认为 NO),完全覆盖了 sprite A。

点击 sprite B,我假设 sprite A 会得到触摸,但没有任何反应。文档中有关此事的部分如下。

我觉得这里有些不清楚,因为 Sprite B 似乎仍然接收到触摸但将其丢弃。 或者,spriteA 已从可能的触摸接收器中移除,因为它不可见。

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

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,它就不应该干扰其他触摸接收器。

更新:即使将 sprite B 的 alpha 设置为 0.2,使 sprite A 非常明显,也不会使 sprite A 可触摸。 Sprite B 只是完全“吞下”触摸,尽管没有启用交互。

最佳答案

这是我的解决方案,直到 Apple 以正确的行为更新 SpriteKit,或者有人准确地弄清楚如何像我们想要的那样使用它。

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

将文件添加到您的项目并将其导入您的 Prefix header 中。现在触摸应该按预期方式工作。

关于objective-c - userInteractionEnabled 设置为 YES 的 Sprite 在被普通 Sprite 覆盖时不会接收到触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19511334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com