简体   繁体   English

处理游戏不同部分的UITouch打开gl ES iPhone

[英]Handling UITouches for different parts of a game open gl ES iphone

A simplified example here: 这里是一个简化的示例:

I have a game that I am writing in opengl es. 我有一个用opengl es编写的游戏。 The game has two different screens that do completely different things based on the user's touch input. 游戏具有两个不同的屏幕,可根据用户的触摸输入执行完全不同的操作。

What is the best way to abstract out the uitouch events from the view? 从视图中抽象出uitouch事件的最佳方法是什么?

I imagine that in a perfect world the touch events would be handled by my game loop, but because the view handles my touch events I don't know how to make the game loop handle them. 我想在一个完美的世界中,触摸事件将由我的游戏循环处理,但是由于视图处理了我的触摸事件,所以我不知道如何使游戏循环处理它们。

Multiple EAGLViews? 多个EAGLViews?

What is the best way to handle touches between two different screens in your game? 处理游戏中两个不同屏幕之间的触摸的最佳方法是什么?

I don't see why you couldn't handle touches in your game loop. 我不明白为什么您不能在游戏循环中处理触摸。 Just record the touch events to a data structure (a list or something) in the views touch handlers. 只需在视图触摸处理程序中将触摸事件记录到数据结构(列表或其他内容)即可。 Then in the game loop just process what ever events have been recorded to the data structure. 然后,在游戏循环中,只需处理已记录到数据结构中的事件即可。 Just make sure that only one thread changes the data structure at a time. 只要确保一次只有一个线程更改数据结构即可。

You don't even need to record the events if more simplified data is enough in the game loop. 如果游戏循环中有更多简化的数据,您甚至不需要记录事件。 In simple cases you could just update variables like touchX, touchY and touchState (none, began, moved, ended) in the touch handlers and read these variables in the game loop. 在简单的情况下,您只需在触摸处理程序中更新touchX,touchY和touchState之类的变量(无,开始,移动,结束),然后在游戏循环中读取这些变量即可。 In this case you may want to make sure that the game loop can react to to both began and ended events in a sensible way. 在这种情况下,您可能需要确保游戏循环可以以明智的方式对开始和结束事件做出反应。 Ie. 就是 began and ended states should always last for exactly one tick. 开始状态和结束状态应始终持续一刻。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM