SetWorldTimeSpeed world,speed#

Parameters

world - the world whose clock to change, such as GetWorld()

speed# - how fast its clock runs: 1 (default) is the cycle's own pace, 2 twice as fast, 0 stops it

Description

Speeds up, slows down or stops a world's time of day.

A time-of-day cycle says how long a whole day lasts in the game, such as 20 minutes. This multiplies that pace: speed it up while the player sleeps, slow it down for a long evening, or stop it with 0 to hold the look still, for a cutscene or a game that drives the clock itself with SetWorldTimeOfDay. Negative speeds run the clock backwards.

The clock is the game's, not the wall clock's: only UpdateWorld moves it, by its elapsed time (UpdateWorld 1 is a sixtieth of a second) times this speed. A cycle with a day length of 0 stands still whatever the speed.

For the full story, see the Environment and camera presets guide.

See also: SetWorldTimeOfDay, WorldTimeOfDay, SetWorldTimeSpeed, FadeWorldEnvironment, UpdateWorld.

Example

; SetWorldTimeSpeed Example
; -------------------------

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

world=LoadWorldAsync("../../../samples/appearance/daynight.world")
While Not WorldReady(world)
    If WorldLoadState(world)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(world)
    UpdateAsyncLoads 2
Wend
SetWorld world
camera=FindWorldEntity(world,"camera")
speed#=1

While Not KeyDown(1)

    ; + and - speed the clock up and slow it down; space stops it
    If KeyHit(13) Then speed=speed*2
    If KeyHit(12) Then speed=speed/2
    If KeyHit(57) Then speed=0
    If speed=0 And KeyHit(28) Then speed=1
    SetWorldTimeSpeed world,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

    UpdateWorld
    RenderWorld

    Text 0,0,"Arrow keys: move camera   + / -: faster, slower   Space: stop   Enter: go   Esc: exit"
    Text 0,20,"SetWorldTimeSpeed world,"+speed
    Text 0,40,"The time is "+WorldTimeOfDay(world)

    Flip

Wend

End

Index