Weird drawing behavior

Monkey Forums/Monkey Programming/Weird drawing behavior

Fryman(Posted 2012) [#1]
Edit:

Scratch that I just worked out why, need to draw all the splats before the enemys not 1 then the other.

Stupid Me





Im experiencing something very weird when I run my code

Basically when you click an object it is destroyed and a "splat" is left in its place, I wanted the other objects to be able to walk over the splats drawing code to be drawn last..

However when compiling the splats are still drawn first, even deleting the build and clearing the browser cache did not fix the problem

The draw code is not called anywhere but the on render method

Original Code:

Method OnRender()
Local I:Int = 0
Cls(255,255,255)
DrawFood
For I = 1 to 100
	If I < 51 then 
		Enemys[I].Draw
		Enemys[I].Move
	EndIf
	Splats[I].Draw
Next



Changed code, but still draws in the wrong order ingame


Method OnRender()
Local I:Int = 0
Cls(255,255,255)
DrawFood
For I = 1 to 100
	Splats[I].Draw	
	If I < 51 then 
		Enemys[I].Draw
		Enemys[I].Move
	EndIf
Next




Paul - Taiphoz(Posted 2012) [#2]
If you think about it in terms of the array, you draw a splat if its available, then you draw an enemy on top of it, but your next splat draw is always going to be over your last enemy draw.

Break it down into two for loops, in the first one draw your splats, then in the second one draw your enemy.

Method OnRender()
Local I:Int = 0
Cls(255,255,255)
DrawFood

'Draw Splats...
For I = 1 to 100
	Splats[I].Draw	
Next

'by this point all possible splats are drawn. 
'your enemies cant be drawn under them now.

For I = 1 to 100
	If I < 51 then 
		Enemys[I].Draw
		Enemys[I].Move
	EndIf
Next