我想在画布上为我的脚本创建一个背景,使图像在屏幕上下落并旋转。那么有人能够向我解释如何旋转图像,然后使用该<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);
};
Run Code Online (Sandbox Code Playgroud)
我尝试这个,发现图像旋转,但也在屏幕上围绕点 (0,0) 移动,我希望它保持在原地旋转的同一位置。我该如何解决这个问题谢谢!