onUpdate(tag: Tag, action: (obj: GameObj)=>void): KEventController

Register an event that runs every frame (~60 times per second) for all game objs with certain tag.

paramtag- The tag to listen for.

paramaction- The function to run when the event is triggered.

// move every "tree" 120 pixels per second to the left, destroy it when it leaves screen
// there'll be nothing to run if there's no "tree" obj in the scene
onUpdate("tree", (tree) => {
    tree.move(-120, 0)
    if (tree.pos.x < 0) {
        destroy(tree)
    }
})

returnsThe event controller.

sincev2000.1

onUpdate(action: ()=>void): KEventController

Register an event that runs every frame (~60 times per second).

paramaction- The function to run when the event is triggered.

// This will run every frame
onUpdate(() => {
    debug.log("ohhi")
})

returnsThe event controller.

sincev2000.1

kaplay logo

Misc

Layer