Overiding the Compare method affects the SortList() command. Which means that you can sort and list of objects by whatever field you like. All you have to do in your main loop is call "SortList(YourList)".
In the example below I've overidden the compare method to z order my sprites sprites:
In the example below I've overidden the compare method to z order my sprites sprites:
Strict 'The Sprite Type Type Sprite Field x:Float Field y:Float Field color:Int [3] '--- Create a Sprite Function Create:Sprite () Local s:Sprite = New Sprite s.x = Rand(0,640) s.y = Rand(0,480) s.color = [Rand(0,255),Rand(0,255),Rand(0,255)] SpriteList.AddLast(s) Return s End Function '--- Render the Sprite Method Render() SetColor color[0], color[1], color[2] DrawOval x-16,y-16,32,32 End Method '--- Here we overide the compare method to '--- look at the "Y" field and compare it with the '--- the given object. Method Compare( other:Object ) Return y-Sprite(other).y End Method EndType Graphics 640,480,0 'Create the Spritelist Global SpriteList:tList = CreateList() '--- Create the Player Sprite Local player:Sprite = Sprite.Create() '--- Create Some Sprites For Local i = 1 To 100 Sprite.Create() Next 'MAIN LOOP While Not KeyHit(KEY_ESCAPE) Cls '--- Sort the Sprites SortList (SpriteList) '--- Render All Sprites For Local s:Sprite = EachIn SpriteList s.Render() Next '--- Update Player Position player.x :+ (KeyDown(KEY_RIGHT) - KeyDown(KEY_LEFT))*2 player.y :+ (KeyDown(KEY_DOWN) - KeyDown(KEY_UP))*2 FlushMem Flip Wend