Android Game Lag on Android

Monchan

Member
Hi everybody,

I'm currently developing a mobile game for Android. I've noticed however when I export the project to an APK and test it on my mobile device, the game often lags. This never occurs on the PC version in GMS2.

Are there any settings I can edit that will help the game lag less? Also, I have other mobile games on my phone that do not lag, so I believe it's a GMS2 issue.

Any help is appreciated. Thank you.
 

Ommn

Member
If you have a lot of resources in your game (images, sounds, codes)

Try not to load all the resources at the beginning of the game.

You can add some resources that you do not use frequently in included Files and load them when needed.
 
Much of it depends on how many objects are loaded into the memory at given room. I had a lot of trouble with it initially. Mobile devices have good deal of problems when it comes to dealing with too many loaded objects and resources. It's highly recommended to keep loaded resource count to minimum and read / load the rest from the files as needed.

You can profile a game by running it in a Debug Mode, where you can clearly see how much of every resource us being used. I recommend keeping base RAM usage as low as possible, and watch out for the unnecessary object count.
 

FoxyOfJungle

Kazan Games
Keep in mind that also some functions can be heavier, like collisions, so it's important to keep in mind the way you're making the game, look at the logic. Try debugging to see what else is consuming resources. An example: The player colliding with the coins is more efficient than the coins colliding with the player, because in the first case I only check the collision once. On windows you can't tell the difference, but cell phones are less powerful than computers (generally).

You can also opt for a 16-bit image instead of 32, which makes the game lighter. Modify this in the game's graphical settings, in the Android tab.
 

Monchan

Member
Keep in mind that also some functions can be heavier, like collisions, so it's important to keep in mind the way you're making the game, look at the logic. Try debugging to see what else is consuming resources. An example: The player colliding with the coins is more efficient than the coins colliding with the player, because in the first case I only check the collision once. On windows you can't tell the difference, but cell phones are less powerful than computers (generally).

You can also opt for a 16-bit image instead of 32, which makes the game lighter. Modify this in the game's graphical settings, in the Android tab.

Thanks so much again Foxy, and everyone else.

I just wanted to mention that, throughout the course of production on this app, I went through 2 phones. The LG K20V and the Moto G Stylus. I'm not sure if those phones have a poor processing power or what.

Could the ndk/sdk versions affect the lag? It doesn't lag on all phones. It doesn't lag on my programmers phone.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Use the show_debug_overlay function and check your texture batches and swaps... On mobile these can be the deciding factor and you want them as low as possible... Like 20ish at most! Post a screenshot of the game with this active so we can see it... Also run the game using the debugger and activate the profiler to see any potential bottlenecks in your code. Finally, if you use particles, keep them to a minimum as they can be an issue on some devices.
 

Roderick

Member
Phones have a widely variable level of performance. If you're developing for mobile, you need to keep lower spec models in mind. Unlike PCs, you can't tell mobile users to upgrade their video card or add some RAM; they're stuck with the specs they have until they replace the entire device.

It might be a good time to refactor your code. Go through your code, especially the blocks that run every frame (Step, Draw, etc), and see if you're doing really heavy work every frame. If you have complicated calculations that take multiple steps to complete, see if there's a way to simplify them. If you're doing something every frame that isn't needed every frame, add an if statement and only run the code when needed.

Remember that when they say that your computer can do "millions of calculations a second", a calculation in this case is the reading or writing of a single bit. Every function you call is actually dozens, if not hundreds of calculations. Do everything you can to keep that number as low as possible.

Making your mobile games as lightweight as possible has other benefits, too. Have you ever played a mobile game and had your phone get really hot, or the battery drain really fast? Those are both symptoms of doing too much for the phone to handle, and can actually cause parts of the device to degrade, and fail faster. By writing lightweight code, you're actually helping maintain your users' devices.
 
Top