Const
event.on
me.input.bindKey(me.input.KEY.X, "jump", true); // Edge-triggered
me.input.bindKey(me.input.KEY.Z, "shoot"); // Level-triggered
me.event.on(me.event.KEYDOWN, (action, keyCode, edge) => {
// Checking bound keys
if (action === "jump") {
if (edge) {
this.doJump();
}
// Make character fall slower when holding the jump key
this.vel.y = this.body.gravity;
}
});
Event for pressing a binded key
Data passed : {string} user-defined action, {number} keyCode, {boolean} edge state
Edge-state is for detecting "locked" key bindings. When a locked key is pressed and held, the first event will have the third argument set true. Subsequent events will continue firing with the third argument set false.