falling
Permet à un objet de disparaître lorsqu'il tombe du niveau
require
body()triggers on self
"death""drop"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
margin | number | 0 | |
delay | number | 0.2 |
example
falling({ margin: 0, delay: 0.2}),function falling(p) { const param = { margin: 0, delay: 0.2, ...p } const fallDistance = LEVELS[CURRENT_LEVEL].map.split("\n").length * LEVEL_CONFIG.tileHeight + param.margin return { id: "falling", require: ["body"], hasFallen: false, add() { this.on("respawn", () => this.hasFallen = false) this.on("drop", () => { this.hasFallen = true wait(param.delay, () => this.trigger("death")) }) }, update() { if (!this.hasFallen && this.pos.y > fallDistance) this.trigger("drop") }, }}