[Python / pyGame] Rotate image towards mouse pointer,
Members - Reputation: 122
Posted 08 October 2010 - 09:17 AM
I'm attempting to rotate an image towards a point using pygame. The point is the mouse cursor in this case. Here is an example of my issue (this is only a snippet):
src_image, rect = pygame.image.load('c:\\testimage.png')
screen = pygame.display.get_surface()
# Example values
player_angle = 0
player_position = (100,100)
# Get the mouse point (Something between (0,0) and (1024,800)).
mouse_point = pygame.mouse.get_pos()
# Set the old_center for repositioning after the rotate.
old_center = self.rect.center
# *** Heres my problem, how do I determine what the angle is from the player_angle
# to the mouse_point with only these three peices of information.
angle_to_mouse = ??
image = pygame.transform.rotate(self.src_image, angle_to_mouse)
rect = image.get_rect()
rect.center = old_center
How do I determine the angle from the center point of the player_point to the mouse_point?
Crossbones+ - Reputation: 8213
Posted 08 October 2010 - 09:52 AM