Game Speed
Hi,
I am developing a battle game while creating enemies and bullets for it i use vectors, Problem i am facing is that at the initia stage game's speed is ok , but as i am start adding the objects like enemies and bullets games speed getting reduced , at the last it is very slow,
Can you please give me all tricks to increase the speed.
Dipali
[370 byte] By [
gamesteama] at [2007-11-26 19:22:46]

# 2
Hi gamestream,
There's lots of things you can do to speed up your game, not using Vectors is a big one!
All the following will help your game run at a decent speed, a search on google will also give you good programming tips for producing optimised games on the mobile platform.
- Try and keep on-screen text to a minimum, displaying text is slow.
- Use backward 'for' loops whenever possible, it's slightly faster
- Avoid using 2D/3D/etc arrays, they take up lots of memory and it's slower to access members, use a large array with an offsets array (short[]?) instead
- Use primitives (int, boolean, char, etc) whenever possible, creating objects is slow
- 1 drawImage call for a large image is better than 3 calls to a broken up image
- Draw as little as possible, it's better to check yourself if an enemy is on-screen rather than just calling drawImage and letting the JVM decide not to draw it
- keep method calls to a minimum, avoid methods like getX() for an enemy, this will add size to your jar, heap and will slow your game down
- use System.currentTimeMillis() with Thread.sleep() to control your game loop, Timers are dodgy and you can easily automatically adjust the sleep time for when the game is very busy
- keep the code to a minimum in methods such as keyPressed, this will delay repaints, simply set an integer to indicate what key was pressed and let your update method do the work
- re-use objects (such as an enemy dying) rather than creating a new one
- it's better to have background music than sound effects, many phones only support one sound loaded at a time, so you will notice delays when a different sound effect is loaded
- Using local variables are faster then class variables
- Avoid methods in loops, such as (for int i=0; i<enemy.size(); i++)
- Avoid creating and destroying arrays, re-use them
- Be sensible in your collision detection, if your game is a side-scrolling shoot 'em up check the X co-ordinates first before Y, there'll be less ships at your X co-ordinate which means less enemies to check for Y collisions.
- use the smallest bit data type for arrays whenever possible, eg. short offset[] instead of int offset[]
These are the core things I found after working almost four years in mobile game development.
I'll add some more if I can think of any, good luck.
DAN>