views:

240

answers:

1

A simplified example here:

I have a game that I am writing in 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?

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?

What is the best way to handle touches between two different screens in your game?

+1  A: 

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. 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.

Lauri