1
所以我用一個在線教程(僅限WebPro.com)來讓我的聖誕老人在我的屏幕上運行。但它不會移動。我正在使用frameCount,所以我不明白爲什麼它沒有移動。誰能幫我?請容易對我,我是一名學生。Sprite工作表不會工作
<html>
<head>
<meta charset="UTF-8" />
<title>Santa</title>
</head>
<body>
<canvas id="myCanvas" width="1000" height="1000">
Sorry, your browser doesn't support canvas technology
</canvas>
<script>
var width = 100,
height = 100,
frames = 5,
currentFrame = 0,
canvas = document.getElementById("myCanvas");
ctx = canvas.getContext("2d");
image = new Image()
image.src = 'img/santa-run-sequence.png';
var draw = function(){
ctx.clearRect(0, 0, width, height);
ctx.drawImage(image, 390, 1, 128.333, 210, 100, 500, 128.333, 210);
if (currentFrame == frames) {
currentFrame = 0;
} else {
currentFrame++;
}
}
setInterval(draw, 100);
</body>
</html>