falling
Permet à un objet de disparaître lorsqu'il tombe du niveau
require
body()triggers on self
"drop""death"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, }; return { id: "falling", require: ["body"], hasFallen: false, add() { const fallDistance = LEVELS[CURRENT_LEVEL].map.split("\n").length * LEVEL_CONFIG.tileHeight + param.margin this.on("respawn", () => (this.hasFallen = false)) onUpdate(() => { const fallDown = this.gravityScale >= 0 ? this.pos.y > fallDistance : this.pos.y < -param.margin if (!this.hasFallen && fallDown) { this.trigger("drop") this.hasFallen = true wait(param.delay, () => this.trigger("death")) } }) }, }}