Case study: how to reduce the size of graphics inside the APK package by 86%?
Developer Milan Babuskov (Milan Babuskov) talked about optimizing the size of graphics inside the APK package. We translated the article and share it.
Babuskov is the founder of his own indie studio Bigosaur. In the process of creating the Gods of Sparta card battler, the developer encountered a problem. Due to the wide variety of Android devices, he decided to create 6 graphic assets of different sizes. However, this led to the fact that the final weight of the APK package would exceed 300 MB.
The limit on the maximum size of APK files is 100 MB. The rest would have to be loaded additionally. The developer admits that he himself hates situations when the game takes time after downloading and downloads hundreds of megabytes more. Therefore, he began to look for an approach that would save future users of the project from these problems.
After searching for different ways, the developer decided to save the opaque textures separately in JPG format, and the transparent ones in PNG. This would save space. The main disadvantage of this approach is that 90% of the graphics in the game were just transparent. In addition, the edges of the cards were rounded. Therefore, Babuskov divided each card into two images – the frame and the contents (see figure).
There were 4 types of cards in the game, and each type belonged to only one type of frame. The contents of all the cards were different, but here transparency was no longer required. As a result, instead of 126 maps with a PNG texture, the developer received 126 maps in JPG format and 4 frames in PNG format.
The next thing we managed to save space on was “inverted” images. During the game, the user moves the cards from one part of the screen to another. As a result, the image on the map is mirrored upside down. In order not to store 2 types of images, the developer used the AtlasRegion function.flip() [the game is written in java, – approx. editorial offices]. In order not to flip the whole JPG image, he set the area that requires changes using setRegionY and setRegionHeight. Then I saved what happened in the group with the main images of the cards, and after that I simply wrote in the code “hide” or “show” the resulting image.
As a result, the final size of the APK files was 42MB. This is 86% less than what the developer expected to get at the beginning.
A source: http://gamasutra.com