开发者

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

I have a game out on Android, and it runs in a single thread. Performs the work in run() a开发者_JS百科nd 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜