HaxeFlixel/flixel — pull request #858 by Gama11 (2014-02-02 08:12:55+00:00)
Title: Introduce FlxSort for FlxTypedGroup.sort() to improve performance

FlxTypedGroup.sort() was *awful* previously. It used sortHandler() on the members array - which uses Reflection. *Reflection in performance critical code!* This means that if you were to sort the bunnies in FlxBunnyMark by their y values, there would be almost 10k calls to Reflect.getProperty(), resulting in about 15 (!) fps. And that's just for 500 bunnies! With this, you get a steady 60 fps for 500 bunnies, and still around 40 for 1500 (all tested in flash and with a sort() call in update()). /rant

This new system requires a little more effort on the user end if they want to sort by things other than x and y, but I think it's worth it. For example if you wanted to sort by alpha, you would have to do this:

```haxe
override public function update()
{
sort(sortByAlpha);
}

inline function sortByAlpha(Order:Int, Obj1:FlxSprite, Obj2:FlxSprite):Int
{
return FlxSort.byValues(Order, Obj1.alpha, Obj2.alpha);
}