Android How to properly handle large amount of sprites for Android?

eric1906

Member
Hello,

So I am working on an Android game on GMS2, and the volume of sprites I am going to use is pretty large (> 100MB).
I know how texture pages work, and how to optimize them to avoid too many swaps.

However, considering that Google Play limits application file size (to about 50 or 100MB cant remember exactly), and since importing all graphics into the game will lead to an .apk file larger than the limit, I can not do that.

Since the game is multiplayer (with a master server), I made the client to download those sprites from the server, then add them into the game (sprite_add(...)). But this creates a new texture page for each sprite.

How am I supposed to handle that? I looked everywhere but couldnt find any way to work on texture pages once the game is running.

Thanks!
 

rIKmAN

Member
Hello,

So I am working on an Android game on GMS2, and the volume of sprites I am going to use is pretty large (> 100MB).
I know how texture pages work, and how to optimize them to avoid too many swaps.

However, considering that Google Play limits application file size (to about 50 or 100MB cant remember exactly), and since importing all graphics into the game will lead to an .apk file larger than the limit, I can not do that.

Since the game is multiplayer (with a master server), I made the client to download those sprites from the server, then add them into the game (sprite_add(...)). But this creates a new texture page for each sprite.

How am I supposed to handle that? I looked everywhere but couldnt find any way to work on texture pages once the game is running.

Thanks!
The initial APK is limited in size to 100MB, but that is raised to 150MB if you use Android App Bundles.
If that is still to small then you can make use of APK Expansion Files which can be up to 2GB in size each.

Info on both can be found here: https://developer.android.com/google/play/expansion-files
 

eric1906

Member
Thanks for your reply.

I read about expansion files, however, this seems pointless.
It would only allow me to add more images/resources to a zip file, which will be downloaded with the app... But then I still have to do sprite_add() which will create a new texture page for each image.
I cant split the actual resources of my GM project into expansion files (or am i wrong? if so, may you please tell me how to do?)
 

rIKmAN

Member
Rather than loading every individual sprite one by one from the server, pack them into texture sheets and then load in that sheet and draw the relevant sprite you need from it.
This means a whole texture page full of sprites will only use a single sprite_add() call and add a single texture page.

This asset uses a similar system: https://marketplace.yoyogames.com/assets/4543/custom-sprite-framework
A similar thing was also discussed in this thread recently: https://forum.yoyogames.com/index.php?threads/moddable-game-sprites.71310/

Have you actually done any testing and checked the performance of your existing system?
 

eric1906

Member
Thanks for the links. I didnt find this thread when I googled my issue.

No I have not done any testing yet. I work with children and they are creating a "small" game, fightning style like old Pokemon games. So each kid draws (on paper) their own monster and animations and whatever they need, I scan them and add them into the game. Right now the amount of sprites is sustainable, but is increasing at a worrying pace, such as, I am afraid I would exceed the 100MB limit from Google Play.

Right now, I have only tested on windows and the kids tried it with multiple PCs. But the final goal is an Android export.

After reading that other post, it seems the performance hit is very small... And since I would end up loading only the sprites I need for each fight (~60 sprite_add so 60 TP) it should not be much of a performance hit?
But I read somewhere that Android will limit (depending on the device) to sometimes 8, or 16 swaps, and if exceeding this, app is not available for such device. Is it true?

I am sorry to ask all this but I dont have many Android devices, while it works fine on mine, it might not on others... And if I need to rewrite my code I'd better to it now than after I have added every single monster from the kids.
 

rIKmAN

Member
Thanks for the links. I didnt find this thread when I googled my issue.

No I have not done any testing yet. I work with children and they are creating a "small" game, fightning style like old Pokemon games. So each kid draws (on paper) their own monster and animations and whatever they need, I scan them and add them into the game. Right now the amount of sprites is sustainable, but is increasing at a worrying pace, such as, I am afraid I would exceed the 100MB limit from Google Play.

Right now, I have only tested on windows and the kids tried it with multiple PCs. But the final goal is an Android export.

After reading that other post, it seems the performance hit is very small... And since I would end up loading only the sprites I need for each fight (~60 sprite_add so 60 TP) it should not be much of a performance hit?
But I read somewhere that Android will limit (depending on the device) to sometimes 8, or 16 swaps, and if exceeding this, app is not available for such device. Is it true?

I am sorry to ask all this but I dont have many Android devices, while it works fine on mine, it might not on others... And if I need to rewrite my code I'd better to it now than after I have added every single monster from the kids.
You could use AVDs to test your game, but nothing can really replace physical on-device testing, so it might be worth getting hold of a low / medium end device to test on.
More info on using Virtual Devices can be found in this guide: https://help.yoyogames.com/hc/en-us/articles/115000270191

As I mentioned above, you could pack those 60 sprites onto a single texture sheet and sprite_add() just that 1 sprite - meaning 1 texture swap instead of 60 - and it would be worth testing Braffolk's extension I linked above which does this

I'm not sure of the resolution of your game or the size of the characters but that would be a good optimization if the swaps were an issue.

It would be worth testing Braffolk's extension I linked above which does this
I don't believe Android limits the number of texture swaps, but there will be where performance suffers which will be different for each device bases on specs.

Do some tests using AVDs and see, but as I said nothing beats actual hardware testing.
 

eric1906

Member
Yes I know I could use that extension, but thats going to be more work than I expected. For now, I will probably stick to built-in sprites and praise for the kids to get bored before we reach that 100MB.

I will still do some testings on my actual device, and will try to borrow an older one and test the performance impact of many texture swaps.
I dont think android limits that either, I just remember reading somewhere Google Play would make your app unavailable to some low-end devices if there were too many swaps.
If I find anything interesting I will report it here. Thanks again for taking the time to help.
 

Yal

šŸ§ *penguin noises*
GMC Elder
If the game is similar in style to the PokƩmon games gameplaywise, you'd only ever have 6 monster sprites on screen at once (3-vs-3 battle or the pause menu party screen), and most of the time you would only have 2. So I don't think the amount of texture swaps would be the main bottleneck for performance (especially not if the game's also turn-based, since it could let you have a lower framerate than a fast-paced action game).
 

eric1906

Member
Yes I agree. It is a 3 vs 3 so 6 monsters at once, each with a standing, damaged, ko'd animations, and a few spells for each.
As I am using delta times and the server also regularly sends a snapshot I am not worried of desyncs / low frame rates.

My main concern is the Play Store not allowing my game on older devices but I cant seem to find the post where I read Play Store would block your app if too many texture swaps... So it might not even be true actually (english isnt my first language so I might have misanderstood), and the issue wouldnt exist anymore.
 

rIKmAN

Member
Yes I agree. It is a 3 vs 3 so 6 monsters at once, each with a standing, damaged, ko'd animations, and a few spells for each.
As I am using delta times and the server also regularly sends a snapshot I am not worried of desyncs / low frame rates.

My main concern is the Play Store not allowing my game on older devices but I cant seem to find the post where I read Play Store would block your app if too many texture swaps... So it might not even be true actually (english isnt my first language so I might have misanderstood), and the issue wouldnt exist anymore.
I am not aware of that ever being a thing, they'd have no way to know that without some sort of in depth performance testing on the code which I have never heard anything about.

They will block your apps on certain devices based on the architecture you export for, but never because of the amount of texture swaps your game does.
That's a performance issue, not a hardware compatibility issue.
 

eric1906

Member
So I ran a few tests for the fun, and in case someone in the future comes accross the same issue, here are my results
https://www.mediafire.com/file/exfy00frlf49p14/stats.pdf/file

tldr is: performance hit is not negligeable at all, but nothing crazy.

-On PC: 60 Texture Swaps / frame drop fps from 19000 to 9500 (2048*2048 textures), or 12000 fps (256*256)
1000 Texture Swaps (256*256) drops to 4000 fps, and 5000 Swaps drops to 1000 fps.

-On android, on a mid-range tablet (huawei media pad t3), large texture swaps are bad. smaller texture swaps (almost) dont impact unless >200 swaps/frame.

On my old phone I get the same results (no big impact) but the app will crash much sooner due to running out of memory.

If anyone in the future wants to test on his own device, here's the sources+windows exe+apk
https://www.mediafire.com/file/zwhbxq4876nydlh/textureswap.rar/file
 
Top