getSpriteDepth()
Purpose
Get a sprites depth
Description
Gets the visual depth of the sprite. For drawing, sprites will automatically be sorted by their depth from negative (earliest drawing) to positive (latest drawing).
Syntax
depth = getSpriteDepth( sprite )
depth = sprite.depth
Arguments
sprite handle of the created sprite
depth visual depth of the sprite
Example
image = loadImage( "Untied Games/Enemy small top C", false )
ship = []
for i = 0 to 2 loop
ship[i] = createSprite()
setSpriteImage( ship[i], image )
setSpriteScale( ship[i], { 5, 5 } )
setSpriteDepth( ship[i], rnd( 10 ) )
repeat
setSpriteRotation( ship[0], 270 )
setSpriteLocation( ship[0], { 0, gHeight() / 2 } )
setSpriteLocation( ship[1], { gWidth() / 2, 0 } )
setSpriteSpeed( ship[0], { 240, 0 } )
setSpriteSpeed( ship[1], { 0, 120 })
setSpriteColour( ship[0], { 0, 0, 1, 1 } )
while ship[0].x < gwidth() loop
clear()
depth0 = getSpriteDepth(ship[0])
depth1 = getSpriteDepth(ship[1])
if depth0 < depth1 then
printAt( 0, 0, "Red ship is on top" )
endIf
if depth1 < depth0 then
printAt( 0, 0, "Blue ship is on top" )
endIf
updateSprites()
drawSprites()
update()
repeat
Associated Commands