小编Sam*_*ort的帖子

画布动画图像旋转

我想在画布上为我的脚本创建一个背景,使图像在屏幕上下落并旋转。那么有人能够向我解释如何旋转图像,然后使用该<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) 移动,我希望它保持在原地旋转的同一位置。我该如何解决这个问题谢谢!

javascript canvas image rotation

3
推荐指数
1
解决办法
2669
查看次数

标签 统计

canvas ×1

image ×1

javascript ×1

rotation ×1