// in Enjine.KeyboardInput
Initialize: function() {
var self = this;
document.onkeydown = function(event) { self.KeyDownEvent(event); }
document.onkeyup = function(event) { self.KeyUpEvent(event); }
},
IsKeyDown: function(key) {
if (this.Pressed[key] != null)
return this.Pressed[key];
return false;
},
KeyDownEvent: function(event) {
this.Pressed[event.keyCode] = true;
},
KeyUpEvent: function(event) {
this.Pressed[event.keyCode] = false;
}
Sheesh. That's why it's jumping up and down when you use the arrow keys. All keyboard input is based on checking `IsKeyDown`, and nothing else. `event.preventDefault()` please. Why do people do this? .preventDefault() is missing in a huge amount of HTML5 demos that aren't full-screen; surely it's not that obscure.edit: seriously, that's all there is to it. Pop open the console / inspector in your browser of choice, and run this:
document.onkeyup = function(event) { Enjine.KeyboardInput.KeyUpEvent(event); event.preventDefault(); }
document.onkeydown = function(event) { Enjine.KeyboardInput.KeyDownEvent(event); event.preventDefault(); }
Viola. No more jumping. No more keyboard scrolling either, which is why you check if the cursor location / last-clicked location is within your canvas.edit2: that aside, very nice work. Smooth playing and so far no glitches, and highly readable code :)
edit3: if you're on IE, that code is `event.returnValue = false` btw. Yaaay, IE :|