stompController
require
body()triggers on self
"begin stomp""stomps"triggers on others
"stomped"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
stompKey | string | 'down' | |
jumpPower | number | 1200 |
example
stompController({ stompKey: 'down', jumpPower: 1200}),function stompController(p) { const param = { stompKey: 'down', jumpPower: 1200, ...p, }; return { id: 'stompController', require: ['body'], add() { let stomping = false; onKeyPress(param.stompKey, () => { if (!stomping && !this.isGrounded()) { this.jump(-param.jumpPower); stomping = true; this.trigger('begin stomp'); } }); this.onCollideUpdate((obj) => { if (stomping && obj.has('body')) { obj.trigger('stomped'); requestAnimationFrame(() => { if (stomping) { stomping = false; this.trigger('stomps'); } }); } }); this.on('respawn', () => (stomping = false)); }, };}