health(hp: number, maxHP?: number): HealthComp
Handles health related logic and events.
param
hp- The initial health points.
param
maxHP- 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")
})
returns
The health comp.
since
v2000.0
group
Components