2D Toolkit Forum

2D Toolkit => Support => Topic started by: XpandeR on October 20, 2013, 08:56:00 pm

Title: Runtime scale all sprites in specific atlas
Post by: XpandeR on October 20, 2013, 08:56:00 pm
Hello.
Is it possible to scale all sprites belonging to specific atlas in runtime?
I know, it is possible to scale each sprite in runtime, but I'm looking a generic atlas-side solution for this. So that I will not need to update the code each time I add new sprite to  this collection.
Title: Re: Runtime scale all sprites in specific atlas
Post by: unikronsoftware on October 20, 2013, 09:58:25 pm
You can do this by manually scaling all the vertex positions. Its doable, but it seems like it might be easier to simply set .scale = ZZZ after creating a sprite?
Alternatively, you can add a scale field in the sprite collection and do that on awake / set sprite or something.

Is there any particular reason you're trying to do this?
Title: Re: Runtime scale all sprites in specific atlas
Post by: XpandeR on October 20, 2013, 10:26:23 pm
Quote
Is there any particular reason you're trying to do this?

I have a universal build for phones and tablets. There are 2 cameras: for UI and for World. Scale should be different on tablet and on phone. Most of work is done fine by resolution overrides + zoom on cameras. However part (not all) of UI sprites need to be scaled differently than other UI on the tablet. I already have these specific sprites in a separate sprite collection.

Solutions I see:
1. Scale single UI sprite collection. I already checked this, by settings scale directly in sprite collection and this works fine. But it works in editor and I need it in runtime.
2. Add 3rd camera for these sprites and zoom the camera.

The 1st solution is preferable, because the project is 90% complete and there is a risk to break something, trying to add new camera and split UI sprites on 2 cameras.
I.e. second solution requires more work (I guess) and contains more risks.
Title: Re: Runtime scale all sprites in specific atlas
Post by: unikronsoftware on October 20, 2013, 10:34:27 pm
If you need it at runtime, it'll involve modifying baked sprite collection geometry and such. I think this is far higher risk than adding a camera simply for UI - at least that is pretty much fully contained and the scope is fairly limited.
Title: Re: Runtime scale all sprites in specific atlas
Post by: XpandeR on October 20, 2013, 10:41:37 pm
Ok, it seems I need to go second way with the cameras.

Thank you.