如何更改重叠精灵的触摸优先级

发布于 2024-12-21 22:05:05 字数 329 浏览 4 评论 0原文

有没有办法改变 cocos2d iOS 精灵的触摸优先级?我在屏幕上看到的是多张卡片,它们呈弧形排列,就像您将它们握在手中时一样。因此,在这个设置中,它们重叠,我需要识别触摸是在哪张卡上进行的。我可以测量卡片每个顶点的坐标并确定卡片的可见区域,然后检查触摸是否在该区域内进行(我不能吗?)但我认为会有一种更简单的方法来处理这个问题,说改变触摸优先级?这意味着最靠近屏幕的卡片将具有最高优先级,并且它会在进入背景的过程中不断减少,因此即使同时触摸 2 个精灵(上面和下面的精灵),它也会仅在具有更高优先级的精灵上注册。

在互联网上阅读仅揭示了更改精灵和图层的优先级的方法,以便它定义触摸是在图层还是精灵上进行的,但这不是我想要的。

Is there any way to change the touch priority for cocos2d iOS sprites? What I have are multiple cards on the screen and they are arrayed in an arc, just like it would when you hold them in your hands. So in this setup, they overlap, and I need to recognize on which card the touch was made. I could measure the coordinates of each vertex of cards and determine the visible area of a card and then check if the touch was made inside that area (couldn't I?) but I thought there would be an easier way to deal with this, say changing the touch priority? Which means that the card closest to the screen would have the highest priority and it'll keep decreasing along the way into the background, so that even if the touch was made on 2 sprites at once (the above and below one), it would be registered only on the sprite with higher priority.

Reading on the internet only revealed ways to change the priority for a sprite and layer so that it defines whether the touch was made on the layer or the sprite, but that's not what I want.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2024-12-28 22:05:05

据我所知,默认情况下你会得到这种行为,离你较近(在 z 轴上)的精灵具有优先权。然而,我认为他们也将这一事件传递给了他们背后的人。所以,我认为你需要做的是当它到达你的任何精灵时吃掉该事件。为此,只需在覆盖“touchBegin”方法时返回 NO 即可。希望有帮助。

As far as I know, by default you get exactly that behavior, the sprites closer (on the z ax) to you have priority. However, I think they pass down the event to the ones behind them as well. So, what i think you need to do is to eat the event when it gets to any of your sprites. To do that, just return NO when overwriting the "touchBegin" method. Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文