EntityOrder entity,order

Parameters

entity - entity handle

order - order that entity will be drawn in; 0 (default) draws normally

Description

Sets the drawing order for an entity.

An order value of 0 means the entity is drawn normally, sorted by depth like everything else. A value greater than 0 means the entity is drawn first, behind everything else - perfect for skyboxes. A value less than 0 means the entity is drawn last, in front of everything else - useful for first-person weapons and 3D HUD elements. Higher values draw earlier, so among ordered entities order 2 is drawn behind order 1.

Setting an entity's order to non-0 also disables z-buffering for the entity, so it should only be used for simple, convex entities like skyboxes and sprites - a concave mesh will draw its own polygons in the wrong order.

EntityOrder affects the specified entity but none of its child entities.

See also: EntityAlpha, HideEntity, CreateSprite.

Example

; EntityOrder Example
; -------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
AmbientLight 200,200,200

; A red cube near the camera and a blue cube behind it
near_cube=CreateCube()
PositionEntity near_cube,0,0,4
EntityColor near_cube,255,0,0

far_cube=CreateCube()
PositionEntity far_cube,0.75,0.75,6
EntityColor far_cube,0,100,255

order=0

While Not KeyDown(1)

    ; Space cycles the blue cube's draw order: -1, 0, +1
    If KeyHit(57)
        order=order+1
        If order>1 Then order=-1
    EndIf

    ; Apply the order: <0 = drawn last (in front), 0 = normal z-buffered
    ; drawing, >0 = drawn first (behind everything)
    EntityOrder far_cube,order

    TurnEntity near_cube,0,1,0
    TurnEntity far_cube,0,-1,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Space: cycle draw order   Arrow keys: move camera   Esc: exit"
    Text 0,20,"EntityOrder far_cube,"+order
    If order<0
        Text 0,40,"-1: drawn last - the far blue cube appears IN FRONT"
    ElseIf order=0
        Text 0,40,"0: normal z-buffered drawing"
    Else
        Text 0,40,"+1: drawn first - the blue cube appears BEHIND everything"
    EndIf

    Flip

Wend

End

Index