Time

Time Functions

onTimer

Registers a function that listens for timer events. Your listener function will be called over and over after the end of each timed interval.

name
type
description

listenerFunction*

function

the name of the listener function that you wrote. Takes one input, the world.

interval*

number

the interval between calls to the listener function, measured in milliseconds

Returns

nothing

onTimer(enemySneezes, 2000)

getElapsedTime

Returns the elapsed time, in milliseconds, since the animation started.

Returns

number the elapsed time, measured in milliseconds

let currentTime = getElapsedTime()

resetTime

Resets the elapsed time that is used by getElapsedTime.

Returns

nothing

resetTime()

setFrameRate

Sets the desired frame rate (in frames per second) for the animation. If you specify a frame rate that is too high, your animation may run at a slower frame rate as limited by your graphics hardware. The frame rate defaults to 60 frames per second.

name
type
default
description

framerate*

number

-

The frame rate that you want (in frames per second)

Returns

nothing

setFrameRate(60)

displayFPS

Makes your program display the actual frame rate (in frames per second) in the Python Shell window every few seconds as your program runs.

name
type
default
description

interval*

number

-

The number of seconds between FPS reports. Use 0 to disable displaying FPS values.

Returns

nothing

displayFPS(2)

getActualFrameRate

Returns current frame rate, in frames per second, of your program. This may be lower than the frame rate you asked for if your program has too much work to do during each frame and can’t keep up.

Returns

number The frame rate in FPS (frames per second)

let fps = getActualFrameRate()

Last updated