Function

loop

(t: number, action: () => void, maxLoops?: number, waitFirst?: boolean): TimerController

Run the function every n seconds.

param t- The time to wait in seconds.

param action- The function to run.

param maxLoops- The maximum number of loops to run. If not provided, it will run forever.

param waitFirst- Whether to wait for the first loop to start.

// spawn a butterfly at random position every 1 second
loop(1, () => {
    add([
        sprite("butterfly"),
        pos(rand(vec2(width(), height()))),
        area(),
        "friend",
    ])
})

returns A timer controller.

since v2000.0

group Timer

kaplay logo

Layer

Miscalenous