Hello Guest

Author Topic: How to use multiple atlases (HD & SD)  (Read 9413 times)

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
How to use multiple atlases (HD & SD)
« on: April 09, 2013, 02:25:50 pm »
2D Toolkit is amazing and runs great on my iPad 2,3,4 - iPhone 4,4S,5

However the app crashes on iPad 1 and iPad Mini due to not enough memory crashes.

What I have been doing is just importing my textures as full resolution, using 4096x4096 sprite atlases - and then just letting Unity does the rest (I assumed unity was scaling the atlases down).

What is the best practice here to support the devices with less memory?

If I could get some specific steps on how to create and use lower resolution atlases that would be helpful. Also - let me know if my texture import process and atlas creation is wrong the way I am doing it.

Thanks,
Mark

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to use multiple atlases (HD & SD)
« Reply #1 on: April 10, 2013, 12:18:17 am »
Unity won't automatically scale the textures down.

You have a 2 options here:

1. Make sure your atlas has mipmaps - you can set this in the sprite collection settings. After that, as soon as your game starts, and before any atlases are loaded in, use QualitySettings to halve texture sizes. Set up a quality setting to have half resolution textures, and then tell Unity to use that. This is the easiest and quickest way to do this. I'd try this first before the other option.
http://docs.unity3d.com/Documentation/Components/class-QualitySettings.html
http://docs.unity3d.com/Documentation/ScriptReference/QualitySettings.html

2. Option 2 - use platform sprite collections. You will need to manually create half size source textures in this version of 2D Toolkit.
http://unikronsoftware.com/2dtoolkit/doc/advanced/platform_specific_sprite_collections.html


m4ko

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 75
    • View Profile
Re: How to use multiple atlases (HD & SD)
« Reply #2 on: April 11, 2013, 01:37:50 pm »
Hi. I have a question related to this:

We have a project which runs at these two resolutions:
1200x900     (4:3)     PC
2048x1536   (4:3)     iPad

- The pc version comes first and is developed at the lower resolution
- After this we want to port this to the iPad
- We don't want to supply the high-res textures to the PC version (its web player based and would load too long)

How would one transfer from PC to iPad without the need to re-arrange everything. I tried to use the 2nd option you gave (platform sprite collections). But this ONLY works with a scaling of 50%, 100%, 200%. It does not seem to work with our scaling of 58.6% (1200 -> 2048).


I also tried camera overwrite:
Spritecollections: SC_A  SC_B

SC_A has the 1200x900 assets
SC_B has the 2048x1536 assets

Scene is set up with SC_A in 1200. I set a resolution override to 2048 and force editor window to 2048. Looks fine. Swapping between 1200/2048 is perfectly fine. However now I change from the upscaled sprites from SC_A to the native 2048 ones in SC_B by just changing the sprite collections by hand. Now the image is scaled too big (because of upscaling from 1200 to 2048 is still in there). I disable "autoscale" on override. Set it to "pixel perfect". The SC_B sprite is now in correct size, but at a wrong position.


Any ideas on how to tackle this?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to use multiple atlases (HD & SD)
« Reply #3 on: April 12, 2013, 12:23:41 am »
Platform sprite collections actually do work with non-multiple of 2 scales, just add what you want in tk2dSystem.assetPlatforms

I would set up something between 1x and 2x, to get the scale correct for your new collection.
The idea was to allow users to set this up in the editor, but it was too error prone - it was too easy to set things up wrong.

The other thing with platform collections is that you can tweak the resources directory, so you don't include all platforms in the build. Again this isn't offically supported, but its straightfoward enough - rebuild the index, then go throug the resources folder finding the tk2d_ files in there, loading them in and then deleting the ones with references to any platform you don't want. The whole system is designed with this in mind, but as I've never required this in our own projects, this was never implemented.

Hope that answers your quesiton...

m4ko

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 75
    • View Profile
Re: How to use multiple atlases (HD & SD)
« Reply #4 on: April 12, 2013, 09:05:04 am »
Thank you very much. I just tested the scaling and and it works beautifully. Very well implemented.

The platform collection tweaking seems a bit trickier. I now have setup a 1x and a 1.7x version. Both atlases are created ok. I can switch between them in the "2d toolkit"->"Preferences" menu and the correct 1x or 1.7x sprites show up. But when I build the scene only the currently active version is compiled into the scene asset.

This is actually what I want. But I wonder how to set it up so that BOTH versions get compiled and I can choose which to use through code.

Also: Whats the best way to use the currentPlatform switch? I set up sprites through scene editor and through code. So I guess I will have to run a "set platform" scene before my gamescene to ensure everything gets loaded from the correct atlas?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to use multiple atlases (HD & SD)
« Reply #5 on: April 13, 2013, 01:38:16 pm »
The currently active version compiled into the scene asset is a serious bug in Unity 4.x. Bug report filed, but as with most other things I've not heard anything since :(

Both versions will get saved, but not in the scene - they are saved in with the resources folder and loaded in as needed. On startup, a sprite with platform collections will load the appropriate one based on currentPlatfom.

The best way to set currentPlatform is in Awake from a script - make sure the script runs before everything else using script execution order.

m4ko

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 75
    • View Profile
Re: How to use multiple atlases (HD & SD)
« Reply #6 on: April 15, 2013, 10:13:26 am »
Ah ok. Well lucky me then.

Thanks for the information. Didn't know about execution order yet.