Created
December 7, 2014 21:49
-
-
Save rounders/fee0cead3c5dcc78919a to your computer and use it in GitHub Desktop.
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
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