Function

onDestroy

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

Register an event that runs when an object with the provided tag is destroyed.

param tag- The function that runs when an object is destroyed.

// This will run when the tagged object is destroyed.
onDestroy("bean", () => {
    debug.log("ohbye");
});

let player = add([
    pos(),
    "bean"
])

// Destroy the tagged object
destroy(player);

returns The event controller.

since v2000.0

group Events

Function

onDestroy

(action: (obj: GameObj) => void): KEventController

Register an event that runs when an object is destroyed.

param action- The tag to match, only called for objects with a matching tag.

param unknown- The function that runs when an object is destroyed.

// This will run when the object is destroyed.
onDestroy(() => {
    debug.log("ohbye");
});

let ghosty = add([
    pos(),
]);

// Destroy the object
destroy(ghosty);

returns The event controller.

group Events

kaplay logo

Layer

Miscalenous