Hi everyone! Just earlier I was experimenting with ctx.rotate property. I came across an issue, in which when I try to rotate the canvas temporarily (within ctx.save and restore) it rotates it based off of a point on the grid. I’m not entirely sure how to explain it…
this is my related code:
this.context.save();
for (let i = 0; i < fireballs.length; i++) {
var fireball = fireballs[i];
let forwardPOS = {
x: fireball.x + 30 * Math.cos(fireball.dir),
y: fireball.y + 30 * Math.sin(firball.dir)
};
this.context.rotate(player.dir);
this.context.beginPath();
this.context.shadowBlur = 10;
this.context.shadowColor = "rgba(0, 0, 0, 0.33)";
this.context.lineWidth = 5.5;
this.context.strokeStyle = "#4e5254";
this.context.fillStyle = fireball.color || "red";
this.context.arc(
fireball.x,
fireball.x,
30,
0,
Math.PI * 2
);
this.context.stroke();
this.context.fill();
// Eyes
this.context.beginPath();
this.context.fillStyle = "#fff";
this.context.strokeStyle = "#4e5254";
this.context.lineWidth = 3;
this.context.ellipse(forwardPOS.x - this.xOffset, forwardPOS.y - this.yOffset, 10 /* width */, 7.5 /* height */, Math.PI, 0 - Math.PI, Math.PI);
this.context.fill();
}
this.context.restore();
Any guidance would again be appreciated!