Blitz3D+ Command Reference

ClearWorld [entities][,brushes][,textures]

Parameters

entities (optional) - true to clear all entities, false not to; true (default)

brushes (optional) - true to clear all brushes, false not to; true (default)

textures (optional) - true to clear all textures, false not to; true (default)

Description

Clears all entities, brushes and/or textures from the world and from memory.

This is the big red button for level changes: when a level ends, one ClearWorld throws away every entity, brush and texture so you can load the next level fresh, without freeing everything by hand.

Gotcha: every handle you were holding becomes invalid - cameras and lights included. Using a cleared handle causes a runtime error, so zero your variables and recreate the camera, lights and listener after each ClearWorld. Anything you want to survive across levels (a player model, say) must be reloaded, or kept out of the clear by passing false for that category.

The three flags let you clear selectively - for example ClearWorld True,False,False removes all entities but keeps loaded brushes and textures cached for the next level, which can make level restarts much faster.

See also: FreeEntity, Graphics3D, RenderWorld.

Example

; ClearWorld Example
; ------------------

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

SeedRnd MilliSecs()

scene_count=0

; Build the first scene
Gosub build_scene

While Not KeyDown(1)

    ; Space wipes EVERYTHING - entities, brushes and textures - then rebuilds.
    ; Note that even the camera is freed, so the scene must recreate it.
    If KeyHit(57)
        ClearWorld
        Gosub build_scene
    EndIf

    ; Spin the hub so the whole scene rotates
    TurnEntity hub,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: ClearWorld and rebuild   Arrow keys: move camera   Esc: exit"
    Text 0,20,"Scene number "+scene_count+" - ClearWorld freed every entity of the last one"

    Flip

Wend

End

; Build a fresh scene: camera, light, and random cubes around a spinning hub
.build_scene
camera=CreateCamera()
PositionEntity camera,0,2,-8

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

hub=CreatePivot()
For i=1 To 8
    cube=CreateCube(hub)
    ScaleEntity cube,0.4,0.4,0.4
    PositionEntity cube,Rand(-3,3),Rand(-2,2),Rand(-3,3)
    EntityColor cube,Rand(50,255),Rand(50,255),Rand(50,255)
Next

scene_count=scene_count+1
Return

Index