views:

209

answers:

3

I am building a 2d OpenGL es application For iPad it displays a background texture and numerous textures on top of it which are always in motion.

Every frame their location is recalculated based on time delta and speed and the entire thing is being rendered at 60 fps successfully, but still as the movement speed of the sprites raises, thing look stuttering.

Any ideas? Are there inherit problems with what I'm doing? Are there known design patterns for smooth animation?

A: 

Try to compute time delta as average of last N frames because it's possible to have some frames that take more time than others. Do you use time delta for animations? It is very important to use it! Also try to load all resources at loading time instead loading them when you use them. This also may slow some frames.

Felics
A: 

Right now what I do is sample time as start of composition and rendering loop than draw the scene as it should be given that time delta. For example if I have a sprite whose speed is 1000 pixels per second and 0.012 is my delta than it is moved 12 pixels. Is that not more accurate than calculating an average of past deltas?

guymic
A: 

If you take a look at the time deltas, you'll probably find they're not very consistent frame-to-frame. This probably isn't because the frames are taking different amounts of time to render, it's just an artifact of the batched, pipelined nature of the GLES driver.

Try using some kind of moving average of the time deltas instead: http://en.wikipedia.org/wiki/Moving_average

Note that even though the time deltas you're observing in your application aren't very consistent, the fact that you're getting 60fps implies the frames are probably getting displayed at fixed intervals (I'm assuming you're getting one frame per display v-sync). What this means is that the delay between your application making GL calls and the resulting frame appearing on the display is changing. It's this change that you're trying to hide with a moving average.

dave