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

Run the function every n seconds.

paramt- The time to wait in seconds.

paramaction- The function to run.

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

paramwaitFirst- 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",
    ])
})

returnsA timer controller.

sincev2000.0

kaplay logo

Misc

Layer