Last active
January 2, 2020 17:17
-
-
Save rendfall/4b27af3b34ab9e98e0db560653e2efdd to your computer and use it in GitHub Desktop.
Phaser - handle keypress input event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Phaser.Scene context | |
const keys = new Set(); | |
this.input.keyboard.on('keydown', (event) => { | |
if (keys.has(event.code)) { | |
return | |
} | |
keys.add(event.code); | |
this.input.keyboard.emit(`keypress_${event.code}`, event); | |
this.input.keyboard.emit(`keypress`, event); | |
}); | |
this.input.keyboard.on('keyup', (event) => { | |
keys.delete(event.code); | |
this.input.keyboard.emit(`keyrelease_${event.code}`, event); | |
this.input.keyboard.emit(`keyrelease`, event); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment