Author Topic: probs with swapping atlases  (Read 3710 times)

tobu

  • Guest
probs with swapping atlases
« on: May 24, 2012, 06:54:39 PM »
We're currently developing an app using ngui, and most things work out nicely, as expected. However we ran into some glitches when swapping simple sprites for animated sprites (using a slightly hacked version of UISpriteAnimation.cs).
What we are trying to achieve is having all "still" sprites in a single truecolor atlas for a crisp look, then swapping them with sprite sequences from bigger, compressed (and shared) atlases shortly before running their animations.
The idea is that while being animated, the lesser, compressed quality won't matter much while we can save some precious RAM on lower end devices.

It basically works, but everytime we swap atlases, spritenames and namePrefixes - a wrong sprite will show up for 1 to 4 frames before the animation continues to play the right ones. That glitch is too obvious to ignore, sadly.

We tried all sorts of walkarounds, but in the end it seems that every atlas has a "default sprite" - the one you see when you select an atlas prefab in the project view (which doesn't necessarily correspond with the numbering in the atlas maker or in the sprite names).

At this point I think we tried all possibilities your otherwise superb framework is giving us, but I might be missing something here...

We're currently first setting atlas, spriteName, namePrefix, after that calling MarkAsChanged, MakePixelPerfect and finally RebuildSpriteList - but whatever order we tried, it didn't seem to make much difference, the "default sprite" will still be visible before things continue as intended.

The simple solution would be to have one "animation-atlas" per sprite, but...
Is there a way to set this "default sprite" so we can keep our animation-atlases shared among sprites?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: probs with swapping atlases
« Reply #1 on: May 24, 2012, 09:35:14 PM »
This might be an order of execution issue. Try adjusting the execution order of the script that does the swapping. You can also try calling UIPanel's Refresh function after rebuilding your sprite list and see if that helps.

tobu

  • Guest
Re: probs with swapping atlases
« Reply #2 on: May 25, 2012, 03:19:12 AM »
Quote
This might be an order of execution issue. Try adjusting the execution order of the script that does the swapping.


Well, we tried this many times... to no avail. That's why I've come to the point of even posting in a support forum... ^^

Quote
You can also try calling UIPanel's Refresh function after rebuilding your sprite list and see if that helps.

Huh, working with 2.0.7, neither me, nor the documentation, nor the compiler have ever heard of such method...

> 'Refresh' is not a member of 'UIPanel' <

Tried the panel's UpdateDrawcalls(), MarkMaterialAsChanged(), different panel settings, clipping on/off - but it also didn't help...

loopyllama

  • Guest
Re: probs with swapping atlases
« Reply #3 on: May 25, 2012, 05:21:36 AM »
To me, the simple solution would be to have two gameobjects per animated sprite...one that uses the static sprite atlas and one that uses the animated sprite atlas. For instance you have a sprite of a truck that uses a high res unanimated atlas, and a second sprite that is set to the first frame of a compressed animated atlas in the inspector, not in script. Both sprites sit at the same x, y, z. The second compressed sprite is hidden, the first sharper static sprite is visible. When the truck is ready to animate, deactivate sprite 1 and activate sprite 2. This removes the need for access to the "default sprite", because the 2nd gameobject is already set to the "starting sprite" in the editor.

Getting around the above solution would only save you the extra quad for each sprite. That doesn't seem worthwhile!
Perhaps I misunderstand your problem though...
« Last Edit: May 25, 2012, 05:23:48 AM by loopyllama »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: probs with swapping atlases
« Reply #4 on: May 25, 2012, 10:20:51 AM »
I just double checked, UIPanel.Refresh is there. It's not in the docs yet because it was added in 2.0.7.

tobu

  • Guest
Re: probs with swapping atlases
« Reply #5 on: June 01, 2012, 04:33:46 AM »
thanks loopy, your suggestion lead me to a better solution in the end...

aren, thanks for checking that. It's kinda strange on my end though, calling Refresh() doesn't work - perhaps I've messed up my project a bit when upgrading to 2.0.7...

anyways, problem (sort of) solved