Last active
January 3, 2016 17:29
-
-
Save caubry/8495827 to your computer and use it in GitHub Desktop.
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
InputEngineClass = Class.extend({ | |
keyState: new Array(256), | |
//----------------------------- | |
setup: function () { | |
document.getElementById('my_canvas').addEventListener('mousemove', this.onMouseMove); | |
document.getElementById('my_canvas').addEventListener('keydown', this.onKeyDown); | |
document.getElementById('my_canvas').addEventListener('keyup', this.onKeyUp); | |
}, | |
//----------------------------- | |
onMouseMove: function (event) { | |
var posx = event.clientX; | |
var posy = event.clientY; | |
}, | |
//----------------------------- | |
onKeyDown: function (event) { | |
var keyID = event.keyID; | |
this.keyState[keyID] = true; | |
}, | |
//----------------------------- | |
onKeyUp: function (event) { | |
var keyID = event.keyID; | |
this.keyState[keyID] = false; | |
}, | |
//----------------------------- | |
update: function() { | |
KeyW = 87; | |
if(this.keyState[KeyW]) | |
console.log("FORWARD!!!"); | |
} | |
}); | |
gInputEngine = new InputEngineClass(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment