views:

118

answers:

2

I have a game out on Android, and it runs in a single thread. Performs the work in run() and the draws in onDraw(). Pretty simple.

However, on a Droid it runs much faster than on a G1.

What is a best practice for ensuring that the game runs at the same speed regardless of the device?

+4  A: 

This is typically controlled by the combination of using a "game loop" ( http://gamedesign.wikicomplete.info/game-loop ) where the code loops around and draws frames with a timed interval. When using different devices, frames may take longer to draw so this is typically dealt with by either dynamically adjusting the "level of detail" (LOD) and/or using "frame skipping" whereby you don't draw a frame every loop. In fact there's another question that demos a basic algorithm for this:

http://stackoverflow.com/questions/1212046/allegro-5-game-game-loop-that-runs-at-constant-speed

-Oisin

x0n
very interesting thank you!
Jorgesys
+1  A: 

Running faster is usually a good thing! The best way for ensuring the game runs correctly on any device is to base your updates on the time passed since last update. This keeps the game feeling consistent when running on a faster device.

Otherwise you could add a sleep call on the faster device - but why not run smoother when you can.

Chris Masterton
Because you will use up the battery faster and unnecessarily keep other processes from using the CPU, which the user may want to be able to keep going? Seems to me that if you're going to hog the CPU, there should be an option to be "nice".
LarsH