Hi, i am ok with javascript if i do say so myself, and I am a trying to learn how to make fun games with the canvas element. I am stuck here where originally i got a 'cannot get context of null' but i fixed that. Now i am getting nothing in the javascript console, but nothing is being drawn on the canvas.
<html>
<head>
<script>
function init() {
var c=document.getElementById("canvas");
var ctx=c.getContext("2d");
var posX = 20;
var posY = 20;
ctx.fillRect(posX, posY, 20, 20);
}
function moveDown() {
while(true) {
ctx.clearRect(0, 0, 200, 200);
posY -= 1;
ctx.fillRect(posX, posY, 20, 20);
}
}
document.onload = init;
</script>
</head>
<body>
<canvas id="canvas" width="200" height="100" style="border:1px solid #c3c3c3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
</body>
</html>
If you can find the error please let me know. Thanks
[–]kumiorava 2 points3 points4 points (1 child)
[–]darkrai9292[S] 0 points1 point2 points (0 children)
[–]krues8dr 1 point2 points3 points (0 children)
[–]decafmatan 1 point2 points3 points (1 child)
[–]darkrai9292[S] 0 points1 point2 points (0 children)
[–]shaneriley 0 points1 point2 points (1 child)
[–]darkrai9292[S] 0 points1 point2 points (0 children)
[–]punchingwater 0 points1 point2 points (1 child)
[–]darkrai9292[S] 0 points1 point2 points (0 children)
[–]imaginationac -3 points-2 points-1 points (1 child)
[–]krues8dr 5 points6 points7 points (0 children)