我想在画布上创建一个背景,让图像从屏幕上下落并旋转。所以,有人能够向我解释如何旋转图像并使用<canvas>
元素将其绘制到屏幕上吗?我有以下代码:
Equations.prototype.Draw = function() {
//increases the rotational value every loop
this.rotate = (this.rotate + 1) % 360;
//rotates the canvas
ctx.rotate(this.rotate*Math.PI/180);
//draw the image using current canvas rotation
ctx.drawImage(this.img,this.x,this.y);
//restore canvas to its previous state
ctx.rotate(-this.rotate*Math.PI/180);
};
我尝试过这样做,发现图像旋转的同时也会围绕着坐标点(0,0)以圆形的轨迹移动。我希望它在原地旋转而不移动位置。请问如何解决这个问题,谢谢!