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
int
SpriteListSort
(
string
a,
string
b
)
{
int
iA, iB
;
if
(
int
.
TryParse
(
a
.
Replace
(
mPrefix,
""
)
,
out
iA
)
&&
int
.
TryParse
(
b
.
Replace
(
mPrefix,
""
)
,
out
iB
)
)
return
iA
-
iB
;
return
a
.
CompareTo
(
b
)
;
}
mSpriteNames
.
Sort
(
SpriteListSort
)
;
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.