0
我已經發現如何用畫布旋轉圖像,但是我在創建動畫的同時旋轉和移動圖像時遇到了問題。這是我已經有:html5畫布 - 同時旋轉和移動圖像
var img;
var context;
var processID;
var i = 0;
var rectWidth = 64;
var rectHeight = 64;
window.onload = function(){
var canvas = document.getElementById("canvas");
context = canvas.getContext("2d");
context.translate(canvas.width/2, canvas.height/2);
processID = setInterval(draw,1000/100);
}
function draw() {
if(i <= 360) {
context.clearRect(-canvas.width/2, -canvas.width/2, canvas.width, canvas.height);
context.strokeRect(-rectWidth/2, -rectHeight/2, rectWidth, rectHeight);
context.rotate(1 * Math.PI/180);
i++;
} else {
clearInterval(processID);
}
}
所以,現在我想我的廣場在轉動時移動到頂部。我真的迷失在這裏,並希望得到一些幫助。