v2.2.0: improved mobsprite sorting, more efficient & sorts other visuals
This commit is contained in:
@@ -314,6 +314,12 @@ public class Group extends Gizmo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void sort(Comparator c){
|
public synchronized void sort(Comparator c){
|
||||||
Collections.sort(members, c);
|
//only sort if we aren't already sorted
|
||||||
|
for (int i=0; i < length-1; i++) {
|
||||||
|
if (c.compare(members.get(i), members.get(i+1)) > 0) {
|
||||||
|
Collections.sort(members, c);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -896,13 +896,13 @@ public class GameScene extends PixelScene {
|
|||||||
scene.mobs.sort(new Comparator() {
|
scene.mobs.sort(new Comparator() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object a, Object b) {
|
public int compare(Object a, Object b) {
|
||||||
//elements that aren't CharSprites go to the end of the list
|
//elements that aren't visual go to the end of the list
|
||||||
if (a instanceof CharSprite && b instanceof CharSprite) {
|
if (a instanceof Visual && b instanceof Visual) {
|
||||||
return (int) Math.signum((((CharSprite) a).y + ((CharSprite) a).height())
|
return (int) Math.signum((((Visual) a).y + ((Visual) a).height())
|
||||||
- (((CharSprite) b).y + ((CharSprite) b).height()));
|
- (((Visual) b).y + ((Visual) b).height()));
|
||||||
} else if (a instanceof CharSprite){
|
} else if (a instanceof Visual){
|
||||||
return -1;
|
return -1;
|
||||||
} else if (b instanceof CharSprite){
|
} else if (b instanceof Visual){
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user