health(hp: number, maxHP?: number): HealthComp

Handles health related logic and events.

paramhp- The initial health points.

parammaxHP- The maximum health points.

const player = add([
    health(3),
])

player.onCollide("bad", (bad) => {
    player.hp--;
    bad.hp--;
})

player.onCollide("apple", () => {
    player.hp++;
})

player.onHurt(() => {
    play("ouch")
})

// triggers when hp reaches 0
player.onDeath(() => {
    destroy(player)
    go("lose")
})

returnsThe health comp.

sincev2000.0

groupComponents

kaplay logo

Misc

Layer