HideEntity entity

Parameters

entity - entity handle

Description

Hides an entity, so that it is no longer visible and is no longer involved in collisions or picks.

A classic use is object pooling: create your entities at the beginning of the program, hide them, then copy or show them as needed during the game. This is much more efficient than creating and freeing entities mid-game. Hiding is also the natural way to handle collected pickups, dead enemies waiting to respawn, and menu props.

If you wish an entity to be invisible but still involved in collisions, use EntityAlpha entity,0 instead - a completely transparent entity still collides. The reverse trick (visible but not collidable) is EntityType entity,0.

HideEntity affects the specified entity and all of its child entities - hiding a parent hides the whole model. Use ShowEntity to bring it back.

See also: ShowEntity, EntityAlpha, FreeEntity, CopyEntity.

Example

; HideEntity Example
; ------------------

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

camera=CreateCamera()
PositionEntity camera,0,1,-5

light=CreateLight()
RotateEntity light,45,45,0

; A spinning power-up sitting on a pedestal
powerup=CreateSphere(16)
ScaleEntity powerup,0.5,0.5,0.5
PositionEntity powerup,0,1.5,0
EntityColor powerup,0,255,100

pedestal=CreateCube()
ScaleEntity pedestal,0.75,0.5,0.75
PositionEntity pedestal,0,0,0
EntityColor pedestal,120,120,120

hidden=0

While Not KeyDown(1)

    ; Space toggles between HideEntity and ShowEntity
    If KeyHit(57)
        If hidden
            ShowEntity powerup
            hidden=0
        Else
            ; HideEntity stops the power-up being rendered - it still exists!
            HideEntity powerup
            hidden=1
        EndIf
    EndIf

    TurnEntity powerup,0,2,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: hide/show the power-up   Arrow keys: move camera   Esc: exit"
    If hidden
        Text 0,20,"HideEntity powerup - hidden, but the entity still exists"
    Else
        Text 0,20,"The power-up is visible"
    EndIf

    Flip

Wend

End

Index