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 | |
deadly | boolean | true |
example
falling({ margin: 0, delay: 0.2, deadly: true}),function falling(p) { const param = { margin: 0, delay: 0.2, deadly: true, ...p, }; return { id: 'falling', require: ['body'], hasFallen: false, add() { const fallDistance = this.getLevel().levelHeight() + 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; if (param.deadly) wait(param.delay, () => this.trigger('death')); } }); }, };}