Hello Guest

Author Topic: Runtime scale all sprites in specific atlas  (Read 5534 times)

XpandeR

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Runtime scale all sprites in specific atlas
« 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Runtime scale all sprites in specific atlas
« Reply #1 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?

XpandeR

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Runtime scale all sprites in specific atlas
« Reply #2 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.
« Last Edit: October 20, 2013, 10:31:40 pm by XpandeR »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Runtime scale all sprites in specific atlas
« Reply #3 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.

XpandeR

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Runtime scale all sprites in specific atlas
« Reply #4 on: October 20, 2013, 10:41:37 pm »
Ok, it seems I need to go second way with the cameras.

Thank you.