Right, so here is another post for my tower defense game .. this time I would like to know how to rotate my cannon tower according to the position of the enemy it is locked on.. I know that there is a method in Graphics2D called rotate in which you specify the amount in radians, but every time I use this the screen flickers because I use Graphics to draw everything. So my main question is what is the best way to rotate the tower image, and what is a method/equation to get which way to rotate it? Thanks, cMp

The visual interpretation of atan2 is that it gives you the angle from the origin to the x,y point you give it. The x and y are reversed in atan2 -- you pass it as y,x -- because tan itself is described in those terms (sin/cos, i.e. y/x on the unit circle)

If you want something drawn away from the origin (i.e. most things you draw), you need to translate then rotate. Otherwise you're rotating the axes you translate on, causing you to revolve instead of rotate.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org