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]
# 1

Kindly check out this thread.

http://forum.java.sun.com/thread.jspa?threadID=5139646&tstart=0

I would suggest you to use a profiler and monitor the heap while you are playing the game.

If you do not want to change the design it is advisable to initially set the minimum growable size of the datastructure. i.e. Vector vecObj = new Vector(<alpha>);.

~Mohan

itsmohana at 2007-7-9 21:43:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 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>

Danford666a at 2007-7-9 21:43:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...