This should be pretty simple.
I'd make each image thingy a type so that the postition of each one in the list represents it's 'priority': the first in the list has lowest priority (is drawn first) and the last has highest (drawn last). You can then just use a For/Each loop to draw them in the correct order.
You can then run through the type list backwards to check for a click on each one. As soon as you find an image that has been clicked, make it top priority by moving it to the end of the type list (using 'Insert clicked_thingy After Last thingy_type'). Doing so this way will automatically handle overlapping images correctly.
[edit] OK, I got bored so here's a simple demo of the technique I'm talking about. :)
I'd make each image thingy a type so that the postition of each one in the list represents it's 'priority': the first in the list has lowest priority (is drawn first) and the last has highest (drawn last). You can then just use a For/Each loop to draw them in the correct order.
You can then run through the type list backwards to check for a click on each one. As soon as you find an image that has been clicked, make it top priority by moving it to the end of the type list (using 'Insert clicked_thingy After Last thingy_type'). Doing so this way will automatically handle overlapping images correctly.
[edit] OK, I got bored so here's a simple demo of the technique I'm talking about. :)
Graphics 500,500,0,2 SetBuffer BackBuffer() SeedRnd MilliSecs() Type thingyT Field x%, y% Field width%, height% Field r%, g%, b% End Type For n = 1 To 50 this.thingyT = New thingyT this\width = Rand(30,100) this\height = Rand(30,100) this\x = Rand(0,500-this\width) this\y = Rand(0,500-this\height) this\r = Rand(20,255) this\g = Rand(20,255) this\b = Rand(20,255) Next While Not KeyHit(1) Cls If MouseHit(1) Then update_thingies() draw_thingies() Flip Wend End Function update_thingies() mx = MouseX() my = MouseY() this.thingyT = Last thingyT While this <> Null If (mx >= this\x) And (mx <= (this\x+this\width-1)) If (my >= this\y) And (my <= (this\y+this\height-1)) ; This thingy has been clicked on so make it top thingy. Insert this After Last thingyT Return EndIf EndIf this = Before this Wend End Function Function draw_thingies() For this.thingyT = Each thingyT Color this\r,this\g,this\b Rect this\x,this\y,this\width,this\height,True Color 255,255,255 Rect this\x,this\y,this\width,this\height,False Next End Function