Blitz3D+ Command Reference

UpdateWorld [elapsed_time#]

Parameters

elapsed_time# (optional) - a master control for animation speed; 1 (default)

Description

Animates all entities in the world and performs collision checking.

This is the world's heartbeat: each call advances every playing animation and runs the collision step - comparing each collidable entity's old and new positions, detecting hits registered with Collisions, and applying the stop or slide response. Call it once per main loop, just before RenderWorld.

Gotcha: no UpdateWorld means no collisions and no animation. If entities sail through walls that you are sure have the right types and Collisions pairs, the missing UpdateWorld call is the first thing to check. Collision query commands (CountCollisions and friends) report what happened during the most recent UpdateWorld.

The optional elapsed_time# parameter scales how far all animations advance this update: 1 animates entities at their usual speed, 2 at double speed, 0.5 at half speed. You can feed it a frame delta for framerate-independent animation, or use it for slow-motion effects. It does not scale entity movement you perform yourself.

See also: RenderWorld, Collisions, Animate, CountCollisions.

Example

; UpdateWorld Example
; -------------------

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

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

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

; Give a sphere a simple keyframed animation: left at frame 1, right at frame 60
sphere=CreateSphere(16)
EntityColor sphere,0,200,255
PositionEntity sphere,-2,0,0
SetAnimKey sphere,1
PositionEntity sphere,2,0,0
SetAnimKey sphere,60
sequence=AddAnimSeq(sphere,60)

; Play the animation back and forth (mode 2 = ping-pong)
Animate sphere,2,1,sequence

speed#=1.0

While Not KeyDown(1)

    ; [ / ] change the master animation speed passed to UpdateWorld
    If KeyDown(26) And speed>0.1 Then speed=speed-0.02
    If KeyDown(27) And speed<4 Then speed=speed+0.02

    ; UpdateWorld advances every animation and performs collision checking.
    ; Call it once per loop, just before RenderWorld.
    UpdateWorld speed

    ; 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,"[ / ] : animation speed   Arrow keys: move camera   Esc: exit"
    Text 0,20,"UpdateWorld "+speed+"   AnimTime(sphere) = "+AnimTime(sphere)

    Flip

Wend

End

Index