Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Buey on October 25, 2012, 01:52:07 AM

Title: BUG: UISpriteAnimation sprite list not sorting correctly without leading zeros
Post by: Buey on October 25, 2012, 01:52:07 AM
Image_1
Image_2
Image_3
...
Image_20

will be ordered as

Image_1
Image_10
Image_11

etc. since you're using string sort.

You can use a sort comparator like

  1. int SpriteListSort(string a, string b)
  2. {
  3.         int iA, iB;
  4.  
  5.         if (int.TryParse(a.Replace(mPrefix, ""), out iA) &&
  6.             int.TryParse(b.Replace(mPrefix, ""), out iB))
  7.             return iA - iB;
  8.  
  9.         return a.CompareTo(b);
  10. }
  11.  
  12. mSpriteNames.Sort(SpriteListSort);
  13.  

but this assumes that mPrefix is exact (defaults to string sort otherwise).
Title: Re: BUG: UISpriteAnimation sprite list not sorting correctly without leading zeros
Post by: ArenMook on October 25, 2012, 02:14:59 AM
That's how string sorting works. Just add zeroes and it'll be fine.