HTML5 canvas drawImage with at an angle

后端 未结 3 1085
抹茶落季
抹茶落季 2020-12-05 04:10

I am experimenting with animation in and can\'t work out how to draw an image at an angle. The desired effect is a few images drawn as usual, wit

3条回答
  •  情书的邮戳
    2020-12-05 04:39

    It is interesting that the first solution worked for so many people, it didn't give the result I needed. In the end I had to do this:

    ctx.save();
    ctx.translate(positionX, positionY);
    ctx.rotate(angle);
    ctx.translate(-x,-y);
    ctx.drawImage(image,0,0);
    ctx.restore();
    

    where (positionX, positionY) is the coordinates on the canvas that I want the image to be located at and (x, y) is the point on the image where I want the image to rotate.

提交回复
热议问题