Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Rotating Images towards the mouse (pygame)
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
BBil




PostPosted: Thu Nov 11, 2010 5:01 pm   Post subject: Rotating Images towards the mouse (pygame)

Canada Canada
So i have run into a problem with rotating images using the mouse. I am making a game and the idea is to have the arms rotate so that they will point directly at the mouse at all times. What is the best way of doing this? It would be best if the solution used pygame because that is what I have been using for the project. I have tested out pygame.transform.rotate but the picture does not stay in its x,y coordinates when it rotates, and the image becomes extremely distorted. Any help would be very appreciated!
Canada Canada Canada
Sponsor
Sponsor
Sponsor
sponsor
BBil




PostPosted: Fri Nov 19, 2010 11:27 pm   Post subject: RE:Rotating Images towards the mouse (pygame)

oh great internet menz and womenz provide me with your wisdom!!!
kctan




PostPosted: Tue Nov 30, 2010 12:52 am   Post subject: Re: Rotating Images towards the mouse (pygame)

Post your code?
paragonz




PostPosted: Fri Dec 24, 2010 2:24 am   Post subject: Re: Rotating Images towards the mouse (pygame)

ummm not the best way to do it, but it is an easy fix. make sure that your arm is centered in the picture, it is easier to rotate pictures from the center ;

mx, my = mouse.get_pos()
ang = atan2((my-300),-(mx-400)) # (300,400) is the location where the picture is centered
rPic = transform.rotate(pic,degrees(ang))
x = 400 - rPic.get_width()/2
y = 300 - rPic.get_height()/2
# this gets the dimensions of the new rect that is created when you transform a picture
# you then find the middle of the new rect and subtract it from the center of your picture
screen.blit(rotPic,(x,y)) # you blit the centered image at pos x & y

if your original arm is centered and pointing to the left , this will move it in the correct direction
if it is pointing the other way, change the and to be "ang = atan2(-(my-300),(mx-400))"

btw sorry that i dont know how to put it in code mode, im new to the forums
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: