fallingBlock
Permet à un objet de tomber lorsqu'un autre objet se trouve dessus
triggers on self
"collapse""respawn"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
tag | string | '*' | |
respawnOnFall | boolean | true | |
fallDelay | number | 0.4 | |
respawnDelay | number | 2 | |
collapseDelay | number | 0.2 | |
disappearDelay | number | 0.4 | |
respawnAnimDuration | number | 0.4 |
example
fallingBlock({ tag: '*', respawnOnFall: true, fallDelay: 0.4, respawnDelay: 2, collapseDelay: 0.2, disappearDelay: 0.4, respawnAnimDuration: 0.4}),function fallingBlock(p) { const param = { tag: '*', respawnOnFall: true, fallDelay: 0.4, respawnDelay: 2, collapseDelay: 0.2, disappearDelay: 0.4, respawnAnimDuration: 0.4, ...p, }; return { isCollapsing: false, id: 'falling block', add() { this.onCollide(param.tag, (obj) => this.collapse(obj)); this.on('respawn', () => { this.isCollapsing = false; this.fadeIn(param.respawnAnimDuration); }); }, collapse(obj) { if (!this.isCollapsing && obj.has('body') && this.pos.y > obj.pos.y) { collapsing = true; wait(param.collapseDelay, () => { this.trigger('collapse'); wait(param.fallDelay, () => { this.isStatic = false; if (param.respawnOnFall) wait(param.respawnDelay, () => this.trigger('respawn')); }); }); } }, };}