Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to make sure Android games run at the same speed on any device

Tags:

android

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?

like image 454
Ben Mc Avatar asked Aug 19 '10 17:08

Ben Mc


2 Answers

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:

Allegro 5 game: game loop that runs at constant speed?

-Oisin

like image 59
x0n Avatar answered Oct 05 '22 03:10

x0n


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.

like image 30
Chris Masterton Avatar answered Oct 05 '22 03:10

Chris Masterton