My game on Android lags

Monkey Targets Forums/Android/My game on Android lags

darky000(Posted 2014) [#1]
Hello.

I have a game I tested on my tablet to test with "android game" target. I am using a samsung galaxy tab. I think this is the first version and I am not sure how I can fix the lagging nor where to find the cause of it.

My game however has four 480x800 images on one screen moving so it might be it? it's around 600kb for each one. My game plays a bit similar to flappybirds so I'm really wondering the cause of the slowdown.

Any tips/wisdom or guidelines I should follow here?


Wylaryzel(Posted 2014) [#2]
would it be possible to post any code? Otherwise its guessing into the blue.

Thx


AdamRedwoods(Posted 2014) [#3]
on most mobile devices, it's essential that you use sprite atlases to reduce texture swaps (even the GUI). also, don't draw outside the screen boundaries. do the screen dimension checks yourself.

i have a galaxy tab and i can get 25-30 fps fairly solid.


therevills(Posted 2014) [#4]
What version of Android are you using?


darky000(Posted 2014) [#5]
@Wylaryzel - Not sure what you want me to post.

@AdamRedWoods - I also get a solid 25-30 fps. That's the average fps for Android? Other games like Temple run gets a less lag than mine. Those 4 images are my background that loops back when they get out of the device boundaries. I tested it to just be still and it has the same result.

@therevills - I'm using version 2.2.1


therevills(Posted 2014) [#6]
I'm using version 2.2.1

Are you creating objects in your main game loop?

Because you are using less then Gingerbread, the GC might kick in every time you create a new object - you might want to investigate pooling.


darky000(Posted 2014) [#7]
@therevills - Yes, I am creating new objects everytime for the obstacles. That may be the cause?

EDIT: Ok I've just read about pooling. I'll do this one.

May I just ask some advice on pooling? Since I have challenge obstacles that may use similar objects in one screen. Would it be best I would create 5 instance of all my objects?


therevills(Posted 2014) [#8]
Would it be best I would create 5 instance of all my objects?

Yep, sounds good and just reuse them and place them in different positions when needed.


darky000(Posted 2014) [#9]
Alright. Thanks therevills. :)


AdamRedwoods(Posted 2014) [#10]
I also get a solid 25-30 fps. That's the average fps for Android?

Temple Run is probably android c++, Temple Run 2 is Unity (which is highly optimized).
but yes, for that version of the Galaxy Tab, 30fps is good in my opinion.


darky000(Posted 2014) [#11]
That's a relief to hear. I was thinking my coding sucks big time because I am not too familiar with memory management besides removing objects that are not needed anymore. Anyway, the lag lessens a bit once I did the pooling. (At least not during creation of the object before). I guess the stuttering is caused with only 30fps.

Thanks Adam. :)