我做了一个简单的画布,我开始构建一个游戏。但是当我只尝试运行html脚本时,它不起作用。我知道我不应该问这样的问题,为什么不工作?!?但我现在非常绝望,我希望你们能帮助我
主要问题是画布没有显示,这意味着我认为我的javascript中存在问题..
Thnx太多了!
<html>
<head>
<style>
Body {
background-color: slategrey;
}
</style>
</head>
<body>
<script type="text/javascript">
function Canvas(){
var ctx = document.getElementById('my_canvas').getContext('2d');
var snelheid = 1;
function background(){
this.x = 0, this.y = 0, this.w = ctx.canvas.width, this.h = ctx.canvas.height, this.color = "yellow", this.count = 1;
this.draw {
ctx.fillStyle = "yellow";
ctx.fillRect(0,0,100,100);
//if(this.count>20){Canvas();}
}
}
var background = new background();
function draw() {
ctx.save();
ctx.clearRect(0,0,ctx.canvas.width,ctx.canvas.height);
//draw
background.draw();
ctx.restore();
}
var animateInterval = setInterval(draw,1);
}
window.addEventListener('load', function(event) {
Canvas();
});
</script>
<canvas id="my_canvas" width="450" height="600">
De game werkt niet in je browser... Download een nieuwe browser!
</canvas>
</body>
</html>