Hello Guest

Author Topic: Too Many Spritesheets !  (Read 10138 times)

krithik_b007

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
Too Many Spritesheets !
« on: November 06, 2013, 11:07:08 am »
Hello,

We are facing some problems due to use of more textures . We have some 25 different textures (there are some 10 different stages in the game each has its own background) , and again each texture is created 3 times (iPad Retina , iPad , iPhone) . So that makes around 75 textures !!!
I saw that 2048 texture takes 16 MB & 4096 * 4096 takes 64 MB ! . So when compiling the project unity creates a file called resources.assets and its size becomes more than 1 GB !.
and compiling the project for iOS takes looong time more than 10 mins ! .

I am from cocos2d background , there we use lot of textures & everything works fine .
since we are working on 2d game on unity , there are lot of 2d images , so how we need to proceed  ? . Is there any workaround ?

&

One more question is whether we need to have original images which we used to create sprite sheets  in the resources folder of unity ? or can we delete it ?

I have also attached the Sprite Collection Settings & texture settings screenshot for the reference.

Thank you

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Too Many Spritesheets !
« Reply #1 on: November 06, 2013, 12:10:49 pm »
The original images makes no difference to the build, or resources size. They aren't included in the build.

You can try compressing the images using 16bit / compressed - that will reduce the file sizes. Unity does a terrible job at compressing textures when on disk - well for starters they aren't compressed in iOS build. There is a hack we can do to reduce the file sizes at the cost of load times, which will probably be in tk2d 2.3 or 2.4 - but again this is just a hack around a fundamental issue in Unity.

You can also put stuff into asset bundles, which will reduce sizes as the asset bundles can be compressed as far as I remember.

krithik_b007

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Too Many Spritesheets !
« Reply #2 on: November 06, 2013, 01:15:43 pm »
Thanks for the quick reply .
So when you have plans of releasing 2.3 which will have this feature .

I Guess one more option is to use 2d Planes to create background images , which will save lot of space in texture atlas ?

Thanks .

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Too Many Spritesheets !
« Reply #3 on: November 06, 2013, 01:32:46 pm »
Using planes will save atlas space, but the texture will still occupy a lot of space. It is the texture that is occupying the space.
Edit: Unsure if this feature will be in 2.3 or 2.4 - and I don't have any dates for either yet.
« Last Edit: November 06, 2013, 01:34:42 pm by unikronsoftware »

krithik_b007

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Too Many Spritesheets !
« Reply #4 on: November 06, 2013, 01:56:25 pm »
So if we just have a image of 2048*1536 and we will use this image in Unity 3d's  2d Plane ,still unity will take 32 MB memory space in resources.assets ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Too Many Spritesheets !
« Reply #5 on: November 06, 2013, 02:19:40 pm »
2048*2048 will take 16MB, 2048*1536 will take about 14MB. Not a huge difference. You can get better results by using .png.bytes files, and then Resources.Loading them. You can save a ton of memory that way, but its a pain as you will have to do it manually.

If you have huge backgrounds you don't need to put them into a spriite collection, just use sprite from texture or something similar.

krithik_b007

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Too Many Spritesheets !
« Reply #6 on: November 06, 2013, 04:22:05 pm »
Can you please explain about .png.bytes files, and then Resources.Loading them.
How can we do that ?

Krithik



unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Too Many Spritesheets !
« Reply #7 on: November 06, 2013, 04:31:08 pm »
http://answers.unity3d.com/questions/490255/how-do-i-store-textures-as-png-in-the-final-build.html
Shaderop's solution is what you need to do. Once you get the Texture2D you can feed that directly into the SpriteFromTexture component.

krithik_b007

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Too Many Spritesheets !
« Reply #8 on: November 06, 2013, 05:12:25 pm »
Thanks unikronsoftware
I will look into it  :)

krithik_b007

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Too Many Spritesheets !
« Reply #9 on: November 07, 2013, 03:00:33 pm »
Hello

I tries various methods today , and found that .png.bytes file is the best one  :) , If we do this we can save  20 MB for 2048*2048 in RGBA 32 Bit ! Thats huge memory size if we consider its just one iPad Retina Background .

Do you think by doing this , will it effect the loading time of the game or the scene ?

Also which is the best way to create tk2dsprite from the Texture2D ?

Currently i am using code like

Code: [Select]
tk2dBaseSprite spriteInstance = null;

Texture2D runtimeTexture = new Texture2D (4, 4);
runtimeTexture.LoadImage (imageTextAsset.bytes);

string[] names = new string[] {
"Extracted region",
"Another region",
"Full sprite",
};
Rect[] regions = new Rect[] {
new Rect (79, 243, 215, 200),
new Rect (256, 0, 64, 64),
new Rect (0, 0, runtimeTexture.width, runtimeTexture.height)
};
Vector2[] anchors = new Vector2[] {
new Vector2 (regions [0].width / 2, regions [0].height / 2),
new Vector2 (0, regions [1].height),
new Vector2 (0, regions [1].height)

};



tk2dSpriteCollectionSize spriteCollectionSize = tk2dSpriteCollectionSize.Explicit (runtimeTexture.width/2, runtimeTexture.height/2);

tk2dSpriteCollectionData spriteCollectionInstance = tk2dSpriteCollectionData.CreateFromTexture (runtimeTexture, spriteCollectionSize, names, regions, anchors);

GameObject go = new GameObject ("sprite");
go.transform.localPosition = new Vector3 (-485.0842f, 480, 0);
spriteInstance = go.AddComponent<tk2dSprite> ();
spriteInstance.SetSprite (spriteCollectionInstance, 2);


Is there any easy way to load the Texture2D directly to tk2dsprite ?

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Too Many Spritesheets !
« Reply #10 on: November 07, 2013, 03:24:18 pm »
Due to a high number of support requests from this IP address, I'm going to have to ask you (and the others on your static IP address) to register your copies of 2D Toolkit.

Instructions here:
http://2dtoolkit.com/forum/index.php?index.php/topic,34.0.html

krithik_b007

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Too Many Spritesheets !
« Reply #11 on: November 07, 2013, 03:51:53 pm »
Okay i will do that tomorrow .
Is there any restrictions in support request or anything like that ?

Thanks .

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Too Many Spritesheets !
« Reply #12 on: November 07, 2013, 03:56:36 pm »
No the only rule is just be sensible. We get a significant volume of support requests and registered users get priority.

krithik_b007

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Too Many Spritesheets !
« Reply #13 on: November 07, 2013, 04:21:51 pm »
Ok Sure . I have filled the form.

Thanks .

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Too Many Spritesheets !
« Reply #14 on: November 07, 2013, 06:36:48 pm »
Thanks.

Quote
Also which is the best way to create tk2dsprite from the Texture2D ?
Use the texture from sprite component as I mentioned before, and call Create on it when updating the texture.