SolarTurtle
SolarTurtle

Reputation: 139

Performance in Android Game

I coded a game for android. For each frame I use the same procedure.

So my game runs smooth, but in some moments the game get stuck. I searched with deltaTimes in the methods, but it is not easy to find the problem.

In the picture for the deltaTime between the frames: frame time you can see the peaks. Between the peaks the game runs smoothly.

So my question for you is, do you know a profiler or some similar in eclipse to find the reason for the peaks? Or do you know a website with performance tipps for game development in android?
The garbage collector isn't it, because in the debug console the message does not come.

//EDIT 1: After searching for more performance tipps i added a custom theme class:

<resources>
    <style name="Theme.NoBackground" parent="android:Theme">
        <item name="android:windowBackground">@null</item>
    </style>
</resources>

This gave me a better performance, but there a still high peaks. second performance test

Upvotes: 4

Views: 155

Answers (3)

MPeti
MPeti

Reputation: 621

It definitely seems like garbage collection. To verify this, you can filter for logcat messages starting with "GC_" while running the game.

Others already posted tips for fixing that, here's what I'd add: look at every line containing the new() operator, and think about where the instance created will eventually end its lifetime. If it's during the game, it should be changed.

Upvotes: 0

Stephan
Stephan

Reputation: 16769

You can use traceview to see where do you spend your time.
Profiling with traceview

And there are some best practices provided by Android in order to improve the performance of an app.
Performance Tips

Upvotes: 0

David
David

Reputation: 20073

One of the biggest reasons for these types of spikes are when garbage collection kicks in. Frames stop an slow if you have say an arraylist of bubbles, and each bubble contains an image , you'd use a pooling system to reuse the bubbles rather than letting the garbage collector collect, which would cause these spikes.

Garbage collection should be avoided while your game is running and the assets should be loaded on the start of the game.

Some articles here that may be of use to you..

Avoid using the enhanced for-loop for ArrayLists in Android games

Object pooling for android gaming

Upvotes: 1

Related Questions