Skip to content

Instantly share code, notes, and snippets.

@rounders
Created December 7, 2014 21:49
Show Gist options
  • Save rounders/fee0cead3c5dcc78919a to your computer and use it in GitHub Desktop.
Save rounders/fee0cead3c5dcc78919a to your computer and use it in GitHub Desktop.
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var x = 0;
var y = 0;
function drawShape() {
ctx.fillRect(x, y, 150, 80);
}
function clearCanvas() {
ctx.clearRect(0,0,canvas.width, canvas.height)
}
function moveRight() {
x = x + 10;
clearCanvas();
drawShape();
}
function moveLeft() {
}
function moveUp() {
}
function moveLeft() {
}
function keyClicked(event) {
console.log("a key was clicked " + event.keyCode);
if (event.keyCode == 39) {
moveRight();
}
}
// register an event handler for detecting keyboard events
document.addEventListener("keydown", keyClicked)
drawShape()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment