3
\$\begingroup\$

I am making an iphone opengl es 1.0 game. I am using a fixed timestep with interpolation on the end. One thread only. I am using CADisplayLink to fire the game loop.

First question: is it okay to use CADisplayLink to fire the game loop? i am targeting > 3.1 so that's not an issue.

Real question: What's the proper way to handle user touch input as it relates to my gameloop and adding state to my game. For example lets say when the user touches the screen i want to fire a bullet. I've read that I don't want to actually update my game state in my touch handler function. But I should instead record that touch in an array or something and then on the next gameloop update(dt) i go through the array and updated my game state based on the array items.

is this correct? shouldn't i be storing a timestamp of each touch so i know exactly how to inject it into my game?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

First answer: AFAIK using the CADisplayLink should work just fine (I use it and haven't had a problem with it yet). The CADisplayLink simply makes sure that your OpenGL view only receives update calls when the hardware is ready for a new frame. Based on your assumptions, however, this may make your game skip or lag at some points. You may consider moving to a variable-step time-based approach to smoothly update your game between frames (example can be found here).

Real answer: This is a tough one to answer directly, as everyone has their own opinion on how this works. In general, I would say yes: place the input events into a queue that is processed at the end of every frame. This ensures a few things: 1) user input is processed in the same order it was received; 2) input processing is executed at a known point in time, making mutation of iterated arrays and other potential hazards a non-issue; 3) significantly cuts down on input-related bugs as you now have a single point in your update loop that you can easily step through to see what's happening.

I'm sure there are some who disagree, but this approach has worked well for me in the past, especially for keystrokes and other state-based input. Please let me know what approach you decide to take and if this answer helped out. Until then, good luck!

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .