- Home /
Sprites compression question (their size in build)
Hi. Currently I am working on 2D game for iOS and Android and I have faced one problem with sprites.
Let's assume that we have sprite S (2048x2048). It needs to be imported with Max Size = 2048 and Format = Truecolor (because compressed totally breaking image quality - I don't won't to be killed by designer). Final size of uncompressed file is 16MB. After building testing scene with only one sprite S and unpacking final ipa file I found that sprite S is passing to device uncompressed. Now let's assume that I have lots of different sprites with properties similar to sprite S. And when I install this game on device, actual size of application is really huge (s0 + 16 N, where s0 is size in MB of everything except my sprites and N is count of my sprites). I found it really disappointing, because when I was working with cocos2d I could load into device sprite S as compressed png file with size ~2-4 MB. And on runtime, when I need to load it, it's been uncompressed. In this case actual size of application on device is s1 + 4 N in worst case.
The question. Is it possible to ask Unity3d to send compressed images to device? Or maybe there is asset, library that can handle my problem?
If you want your game to be played on most android devices, you definitely need to use the compression. i know compression mess up with the semi transparent, but you could avoid this with your art style. Like not blending two colors with low hardness, that way the textures loose lot less quality. (this what i do for my game xD)
@edwar, I can't use compression from import settings, because our sprites have lot's of semi transparent and gradients. After compressing everything looks so messed (even I can notice it, lol). Anyway, thank you for your answer.
art style. Like not blending two colors with low hardness, that way the textures loose lot less quality. (this what i do for my game xD)
Oh, I didn't understand this. What are art styles?
For example like this! art style 1 is more likely hand drawing with semi transparents and get messed up when i compress it. bur where as, art style 2, they have only solid colors and when i compress them. they give me almost the same result as uncompressed. :)
Answer by Eric5h5 · Jun 29, 2014 at 03:37 PM
You can store textures as .png files in an external folder, and load those via the WWW class at runtime. The downside is that you lose the usual Unity workflow.
Thank you for your answer. Currently I am using .bytes extension for my images and loading them via
var binImage = Resources.Load<TextAsset>(imagePathInResourcesFolder);
myTexture2D.LoadImage(binImage.bytes);
It's good for me because I can easily load images and unload them to free memory usage :)
This solution helped me save 2/3 of the size of a bunch of shitty jpgs, cheers! :)
Could you please explain more how to implement this solution ?
And how do you build your scenes? I mean you have to sacrifice the unity workflow for that? Just import every texture manually?
Answer by Flailer · Jun 28, 2014 at 09:22 PM
You can't "decompress" an image. The process sacrifices quality for reduced file size, chucking out bytes in the image, these cannot be reclaimed later unless these bytes and their pattern are stored somewhere else. Cocos2d does not "decompress" and get you back your image quality as this is not possible, Unity will do the a similar thing as regards to memory allocation as Cocos2d.
Loss-less compression is as it says, loss-less in quality whilst reducing image size, which brings about the question as to why you'd want to decompress it in the first place.
To put it simply, find a better way of getting your sprites to look good compressed or take the install size hit. Either way its gonna be 16mb in memory as a full RGBA32 bit image... regardless of what u do.
I think this is kind of wrong. Well, maybe not wrong but missing...
Compression has two types: Lossy and Lossless. Lossless compression can be uncompressed without loosing any pixels. That's very possible but I think Unity doesn't support this compression type.
What I saw from my experiments is that the Unity sends image assets is raw to device (so 4096x4096 texture in RGBA32 takes as 64 $$anonymous$$B). But I would like to send on device png file that weights much less (~4 $$anonymous$$B). I understand that in run-time this png will be "decompressed" and will take 64 $$anonymous$$B of RA$$anonymous$$, and it will take time. But I'd rather put LOADING screen than publishing game that weights 2.5 GB for mobile phones. And btw, ipa file of such big application weights only 250 $$anonymous$$B. As expected, zipping can compress lossless.
Yes, you are right Xtro, maybe I didn't expand enough, my first paragraph is about lossy compression and the second about lossless and I'm sort of asking why you'd want to uncompress/ mess with a compression format that loses you no pixels.
Secondly, Unity only sends it "raw" or truecolor if you ask it to. At some point this image will have to be compressed if you want the game smaller. You could look into writing your own lossless compression script for Unity?
Oh, I already found workaround. Look for my comment to Eric5h5's answer. Anyway, thank you for you answer. :)
Your answer
Follow this Question
Related Questions
Assigning a texture for object in inspector. Is it loaded right away? 0 Answers
Displaying an image from a resource folder. 2 Answers
How to get a Texture asset that is in the project and pass it to a function? 3 Answers
Does loading a Resource load that resource's dependencies? 1 Answer
Assigning script-generated textures 0 Answers