I’m working on a game where the player controls a space ship that circles clock/counterclockwise around a center point while shooting projectiles coming from said point. I have everything written, although actual placement is slightly off and rotation isn’t working.
For movement, I have:
if (code==KeyEvent.VK_LEFT) {
trans.setToIdentity();
trans.translate(player.x-10, player.y-10);
player.moveLeft();
//trans.rotate(?)
System.out.println(player.x + " " +
player.y + " " + player.dX + " " + player.dY);
}
Where trans is an AffineTransform, player.moveLeft() changes the player’s coordinates to a point on the circle (working as expected, uses sin/cos/theta, simple trig). When I draw an object with Graphics2D it follows the coordinates, but when I use an imported image it trails by several (~25) pixels. Since I have an angle, x, y, and radius, what can I use with AffineTransform to rotate the image around its center point and have it constantly face the center point?
Figured it out. First move the ship’s center point to the player’s x,y coordinates, and then rotate (with a slight angle tweak) around the center point.