Here is a more complete example, I hope this explains better:
Type Sprite
Field x:Float
Field y:Float
Field z:Float
Field green
Field red
Field blue
Method Compare(other:Object)
If Sprite(other).z < z Return -1
Return 1
End Method
End Type
Graphics 800,600,0
Local sprites:Sprite[3]
sprites[0]=New Sprite
sprites[0].green=255
sprites[0].red=0
sprites[0].blue=0
sprites[0].x=50
sprites[0].y=50
sprites[0].z=5
sprites[1]=New Sprite
sprites[1].green=0
sprites[1].red=255
sprites[1].blue=0
sprites[1].x=150
sprites[1].y=150
sprites[1].z=20
sprites[2]=New Sprite
sprites[2].green=0
sprites[2].red=0
sprites[2].blue=255
sprites[2].x=250
sprites[2].y=250
sprites[2].z=10
Local spriteList:TList=New TList
ListAddLast spriteList,sprites[0]
ListAddLast spriteList,sprites[1]
ListAddLast spriteList,sprites[2]
While Not KeyHit(KEY_ESCAPE)
SortList spriteList
For Local s:Sprite=EachIn spriteList
SetColor s.red,s.green,s.blue
DrawRect s.x,s.y,200,200
Next
Flip
Cls
Wend
- Change the z field for the sprite objects to alter the drawing order.
- You must call SortList on the list whenever you modify the list (add or remove items) or if you modify the z-coordinates of any of the sprites
- I have used a coloured rectangle above, you just need to replace the red,green,blue fields with a field for your TImage object.