Recall, the implementation of Key Events use the following jQuery events.
$(document).ready(function(){
$(this).keypress(function(event){
getKey(event);
});
});
function getKey(event)
{
var char = event.which || event.keyCode;
var actualLetter = String.fromCharCode(char);
}
And we are back in this! How do we create classes and objects again? Start with this.
<html>
<head>
<title>Canvas</title>
<style>
#myCanvas{
border:black;
border-style: solid;
border-width: 2px;
}
</style>
</head>
<body>
<canvas id="myCanvas" height="600" width="800"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var x = 50;
var y = 50;
ctx.fillStyle = "#0000FF";
drawSquare();
setInterval(update, 1000);
function update()
{
drawSquare();
}
function drawSquare()
{
ctx.fillRect(x, y, 20, 20);
}
</script>
</body>
</html>
Now, create a Square class and then use the fillRect above using the object you create.
Using your object and your key events, make sure you can update your object properties and move the square.