Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am developing a simple graphical game for Android (Java and OpenGL ES). There is no high-end graphics involved, basically a few (less than 10) sprites and some (about 10) dynamically drawn primitives. The performance of the game is quite fine, I get about 50-60 FPS on my HTC Desire.

However, there is one specific performance issue. In my game I can fire a characters' gun, which then fires a laser beam that moves over the screen following its velocity vector. This beam is dynmically drawn. The thing is: when I fire the gut the first time, the laser beam is moving very unsteady (its "hopping" over the screen). But, after this first time, when I then fire the gun for how often I like, the laser beam is moving very smooth over the screen.

I first thought this might be an issue with Android's garbage collector. But I double-checked my code. Not one single new object is created within the main game loop, I solely use pre-created objects (i.e. class instances). I also doubt the problem is related to the dynamic drawing of my primitives (laser beam), because as said its working fine and very smooth for every gun shot after the first one. It is solely this first shot where I encounter this performance issue.

So my question is, does this behaviour sound familiar to anyone of you guys? I would appreciate any idea very much.

share|improve this question
    
Some code pertaining to the rendering of the beam and other sprites may help. –  Josh Petrie Jul 27 '11 at 14:53
    
@Josh: what exactly do you mean with "code pertaining"? –  Matthias Jul 27 '11 at 15:27
1  
"Pertaining" meaning "related to;" I'm just asking to see the code that does the drawing of the beam. There's a lot of things that could cause performance hitches like you describe. Showing code might help people provide an accurate answer to your question instead of just guessing at a bunch of random things that might be the problem. –  Josh Petrie Jul 27 '11 at 15:31
    
Why don't you just profile it, and come back to us pointing to the exact offending code? –  Maik Semder Jul 27 '11 at 17:05
    
If all else fails, do the first draw of it behind a loading screen. –  Adam Jul 27 '11 at 21:35
show 1 more comment

2 Answers 2

Try limiting your delta time (time between updates) to 0.1 or something similar - I've read about a bug where sometimes on Android the time is incorrectly reported and could cause an issue similar to the one you're having.

share|improve this answer
add comment

Are you sure that it is not garbage collection happening? You can check the logs in DDMS to see when garbage collection happens. If it's the first time then it's indicative of some object being allocated (or falling out of scope) or textures being allocated.

If you don't see any garbage collection happening then the next step is to profile the function to see exactly which line it hangs on and then figure out what's happening or edit the question so that we can offer suggestions.

While not specifically helpful for your problem but useful for game development on Android in general, you might also like to have a look at the Android Traceview program that lets you profile which calls are taking a long time so that you can optimise them.

Screenshot of Traceview

share|improve this answer
    
thanks for sharing the link, I will give Traceview a try! –  Matthias Aug 29 '11 at 7:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.