| None. |
|
Creates and returns a new, empty 3D world. A world is a complete, self-contained 3D scene: its own entities, cameras, lights, listener, collision setup, and global settings such as AmbientLight. Your program always starts with one - the protected default world - and CreateWorld gives you more. Keep the game scene in one world and build a menu backdrop, a vehicle preview, a minimap scene, or the next level in another; each world updates and renders independently, and entities in different worlds never collide with or see each other. The new world does not become selected automatically: call SetWorld before creating parentless entities, setting up collisions, or rendering it. Textures, brushes, shaders, images, and sounds are not world-owned - handles like these are shared freely across worlds, so a texture loaded once can dress entities everywhere. Worlds from CreateWorld are ready immediately (WorldReady is True). To build a world from a .world scene file in the background instead, use LoadWorldAsync. Free a world you are done with using FreeWorld. See also: SetWorld, GetWorld, FreeWorld, EntityWorld, LoadWorldAsync. |
; CreateWorld Example
; -------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; The default world holds the game scene: a red spinning cube
game_world=GetWorld()
game_camera=CreateCamera()
PositionEntity game_camera,0,1,-5
game_light=CreateLight()
RotateEntity game_light,45,45,0
cube=CreateCube()
PositionEntity cube,0,1,0
EntityColor cube,255,80,80
; CreateWorld returns a fresh, empty, independent world.
; It is not selected automatically, so select it before building its scene
preview_world=CreateWorld()
SetWorld preview_world
preview_camera=CreateCamera()
PositionEntity preview_camera,0,1,-5
preview_light=CreateLight()
RotateEntity preview_light,45,45,0
sphere=CreateSphere()
PositionEntity sphere,0,1,0
EntityColor sphere,80,140,255
; Back to the game world to start with
SetWorld game_world
active_camera=game_camera
While Not KeyDown(1)
; Space switches between the two independent worlds
If KeyHit(57)
If GetWorld()=game_world
SetWorld preview_world
active_camera=preview_camera
Else
SetWorld game_world
active_camera=game_camera
EndIf
EndIf
; Both scenes keep animating, even the one not selected
TurnEntity cube,0,1,0
TurnEntity sphere,0,1,0
; Arrow keys move the selected world's camera
If KeyDown(200) Then MoveEntity active_camera,0,0,0.1
If KeyDown(208) Then MoveEntity active_camera,0,0,-0.1
If KeyDown(203) Then TurnEntity active_camera,0,1,0
If KeyDown(205) Then TurnEntity active_camera,0,-1,0
RenderWorld
Text 0,0,"Space: switch world Arrow keys: move camera Esc: exit"
If GetWorld()=game_world Then scene$="the default game world (red cube)" Else scene$="the created world (blue sphere)"
Text 0,20,"CreateWorld() returned "+preview_world+" - now showing "+scene
Flip
Wend
FreeWorld preview_world
End