problem description
The effect of the rotation angle falling of the picture in canvas has been tossing around for a long time, but there are still some anomalies.
the speed is abnormal after rotation, and the normal speed should be the same speed. It is estimated that it has something to do with my (this.x + Math.tan (deg) * this.y)
code. This sentence is added in order to fall in a straight line after rotation.
is generated at the wrong height. Normally, it should be generated at the top, but some will generate
these two questions are good after removing the rotation-related code. Please point out
key code
context.save();
context.translate(this.x+($el.widths) / 2, this.y+($el.heights) / 2);
context.rotate(deg);
context.translate(-this.x-($el.widths) / 2, -this.y-($el.heights) / 2);
context.drawImage(
$el.image,
0, 0,
$el.widths,
$el.heights,
(this.x), this.y,
$el.widths * this.radio, $el.heights * this.radio
);
context.restore();
I still hope to explain the meaning of moving the coordinate system to the center of the picture, rotating and then translating back. Thank you
.