在 iPhone 上处理多点触控

发布于 2025-01-05 18:40:56 字数 402 浏览 5 评论 0原文

我正在使用 OpenGL 制作 iPhone 游戏。当我开始编写游戏控件的界面时,我遇到了一个问题。我有四个按钮(左、右、攻击、跳跃),我需要能够同时按下 和 。我需要的是一个函数touchesStationary(只有touchesBegin、Moved和End)。我需要一个返回当前屏幕上所有手指的函数(与它们当前的相位无关),但这些函数仅在我开始按下、移动手指或抬起手指时返回...没有当手指保持在原位并按下按钮时的功能。

我尝试使用touchesBegin、touchesMoved 和touchesEnd 编写代码,但其中一个函数返回的手指列表的顺序与其他函数不同,因此它把一切搞砸了,多点触控变得不可能。

理想的功能将返回当前屏幕上的所有手指,然后我可以遍历所有手指,检查它们的位置是否与某个按钮的位置匹配,然后激活该按钮。我怎样才能做到这一点?

I am making an iPhone game using OpenGL. I've run into a problem when I started to write the game controls' interface. I have four buttons (Left, Right, Attack, Jump), and I need to be able to press and simultaneously. What I need is like a function touchesStationary (there are only touchesBegin, Moved and End). I need a function that returns all the fingers currently on the screen (doesn't matter their current phases), but those functions only return when I start pressing, when I move a finger or when I lift a finger... There are no functions for when a finger stays in place, pressing the button.

I've tried to write a code using touchesBegin, touchesMoved and touchesEnd, but one functions returns a finger list that is in different order than the others, so it screws everything up, and multitouch becomes impossible.

The ideal function would return all the fingers currently on the screen, then I can iterate through all of them, checking if their positions match the position of some button, and then activate that button. How can I achieve that?

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

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

发布评论

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

评论(1

潇烟暮雨 2025-01-12 18:40:56

您基本上讨论的是实现大量基于触摸的 GUI 功能,以及由此带来的所有复杂性。您将必须实现一个小型状态机来跟踪每个按钮的情况。例如,按钮一开始处于“未按下”状态。如果您检测到按钮内有触摸,它将转换为“按下”状态。当触摸移动(或结束,或被取消)时,您检查按钮是否仍然包含触摸。如果没有,您将转换回“未按下”状态。您的游戏循环可以检查按钮的状态并相应地生成事件(例如,某些按钮可能需要在按下时连续生成事件,而其他按钮在释放时生成单次事件)。

You're basically talking about implementing a significant chunk of touch-based GUI functionality, with all the complexity that brings. You're going to have to implement a small state machine that keeps track of what's going on with each button. For example, a button starts out in its "not pressed" state. If you detect a touch within the button, it transitions to its "pressed" state. When touches move (or end, or get canceled), you check to see if the button still contains a touch. If it doesn't, you transition back to the "not pressed" state. Your game loop can check the state of the button and generate events accordingly (for example, some buttons may need to generate events continuously when depressed, while others generate a single-shot event when they are released).

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