Rotation Around Center

I found a solution! It was simpler than I thought…

First, when the tile is created, you need to find the hypotenuse using the Pythagorean theorem:

var hypotenuse:Float = Math.sqrt(width / 2 * width / 2 + height / 2 * height / 2);

Then, using Sinus and Cosinus, we’re able to find the center point that we want and compare it with the values of the last frame:

newX = hypotenuse * Math.cos((rotation + 45) * Math.PI / 180);
newY = hypotenuse * Math.sin((rotation + 45) * Math.PI / 180);

x += oldX - newX;
y += oldY - newY;

oldX = newX;
oldY = newY;

I added 45 to the rotation in the equation, because at 0°, the sprite is inbetween 2 axes.

Just be sure that you have the good width and height of your sprite! That was one of my many problems… :stuck_out_tongue:

EDIT: For visual explanations, see the posts below!

1 Like