Created
April 21, 2017 05:43
-
-
Save opparco/a77e03299192f0dd0129fa0e62ce0bc2 to your computer and use it in GitHub Desktop.
handle virtual controller input on RPGAtsumaru
This file contains 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
interface Window { | |
RPGAtsumaru; | |
} | |
class RPGAtsumaruState { | |
buttons; | |
next: Function; | |
create() { | |
this.buttons = { | |
left: {}, up: {}, right: {}, down: {}, ok: {}, cancel: {} | |
}; | |
/** | |
* next | |
* @param event {type: string, key: string} | |
*/ | |
this.next = function(event) { | |
if (event.key in this.buttons) { | |
let isDown = false; | |
if (event.type === 'keydown') | |
isDown = true; | |
this.buttons[event.key].isDown = isDown; | |
} | |
}.bind(this); | |
if (window.RPGAtsumaru) { | |
console.log('window.RPGAtsumaru is defined.'); | |
window.RPGAtsumaru.controllers.defaultController.subscribe(this.next); | |
} | |
else { | |
console.log('window.RPGAtsumaru is undefined.'); | |
} | |
} | |
update() { | |
if (window.RPGAtsumaru) { | |
this._handleInputRPGAtsumaru(); | |
} | |
} | |
_handleInputRPGAtsumaru() { | |
if (this.buttons.ok.isDown) { | |
/* */ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment