Lingo Dictionary > L-N > locZ of sprite |  |

locZ of sprite

Syntax

    sprite(whichSprite).locZ

Description

Sprite property; specifies the dynamic Z-order of a sprite, to control layering without having to manipulate sprite channels and properties.

This property can be tested and set.

This property can have an integer value from negative 2 billion to positive 2 billion. Larger numbers cause the sprite to appear in front of sprites with smaller numbers. If two sprites have the same `locZ` value, the channel number then takes precedence for deciding the final display order of those two sprites. This means sprites in lower numbered channels appear behind sprites in higher numbered channels even when the `locZ` values are equal.

By default, each sprite has a `locZ` value equal to it's own channel number.

Layer-dependent operations such as hit detection and mouse events obey sprites' `locZ` values, so changing a sprite's `locZ` value can make the sprite partially or completely obscured by other sprites and the user may be unable to click on the sprite.

Other Director functions do not follow the `locZ` ordering of sprites. Generated events still begin with channel 1 and increase consecutively from there, regardless of the sprite's Z-order.

Example

This handler uses a global variable called gHighestSprite which has been initialized in the startMovie handler to the number of sprites used. When the sprite is clicked, its locZ is set to gHighestSprite + 1, which moves the sprite to the foreground on the stage. Then gHighestSprite is incremented by 1 to prepare for the next mouseUp call.

    on mouseUp me
    	global gHighestSprite
    	sprite(me.spriteNum).locZ = gHighestSprite + 1
    	gHighestSprite = gHighestSprite + 1
    end

See also

`locH`, `locV`