[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] smooth surface rotate



mike@zcentric.com wrote:
I want to take an image and rotate it around its center over and over
again in around 5 degree changes. pygame.transform.rotate() makes the
image grow. Is there anything i can do to not have the image grow (looks
like its moving across the screen)?
Mike, the two pygame functions that can rotate all enlarge the image. Just the way it goes. Otherwise the corners of the image would get chopped out. But here's some good news and advice for you.

Using the pygame Rect's, it is easy to 'recenter' your rotating images. Assuming you have a Rect helping position your image the code would go like this,

oldcenter = myrect.center
myimage = pygame.transform.rotate(myimage, 20)
myrect = myimage.get_rect()
myrect.center = oldcenter

Another thing to keep in mind. The image rotation is a sort of 'lossy' operation. Everytime you rotate an image the quality gets a little worse. For best results you want to keep a copy of the original image. Then everytime you rotate, rotate from that original image using the total rotated degrees. This will give you the best looking results.

Look at the pygame 'Chimp' example for rotating an image in one place. The monkey does this when you punch him.

http://pygame.org/docs/tut/chimp/ChimpLineByLine.html