Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So I am making an "Asteroids" like game and I can principally get my sprites image to rotate but when I do, the image gets kinda torn apart. This is the method I am using for rotation. Any help would be appreciated.

def turnLeft(self):

   rotatedSurf1 = pygame.transform.rotate(self.image,10)
   rotatedRect1 = rotatedSurf1.get_rect()
   rotatedRect1.center = (25,25)
   self.image.blit(rotatedSurf1,rotatedRect1)
share|improve this question
    
Please define "torn apart", if possible via a screenshot with a before and after part. –  Philip Allgaier Dec 17 '14 at 15:23
    
The image kinda like swirls into a mess of pixels, like it is being blended, it gets worse as you rotate more and more. It might be good to mention also the the image rotates as the player keeps the left arrow key down. –  SyntheticWeb Dec 17 '14 at 16:08
    
You want to change this line self.image.blit(rotatedSurf1,rotatedRect1) to something like self.backgroundSurface.blit(rotatedSurf1,rotatedRect1). –  Syntac_ Dec 18 '14 at 11:45

1 Answer 1

up vote 1 down vote accepted

I'm not familiar with pygame, but likely it does not like the image being repeatedly rotated and blitted onto itself.

Check out if this answer on StackOverflow works for you.

Explanation

Rotating an image is inaccurate. Unless you rotate exactly by multiples of 90 degrees, you never get an exact pixel-to-pixel mapping. In other words, you loose a small amount of information when you rotate. Since you replace the original image with the rotated version, this information is lost forever. Thus, the effect gets worse the more you rotate.

You should never modify the original image. Instead, store the rotation angle in a variable, increase/decrease this angle when pressing left/right, and rotate by that angle. Then, you can store the rotate image (rotatedSurf1, rotatedRect1) as a member variable and blit it to the screen when drawing the scene. Do not blit the rotated image back onto the original!

def turnLeft(self):
    self.angle += 10
    self.rotatedSurf = pygame.transform.rotate(self.image, self. angle)
    self.rotatedRect = self.self.rotatedSurf.get_rect()
    self.rotatedRect.center = (25, 25)

Don't forget to initalize self.angle to 0. In the drawing function instead of doing something like display.blit(self.image), now do display.blit(self.rotatedSurf, rotatedRect).

share|improve this answer
    
I am using this method by storing the surface of the sprite in rotatedSurft1. –  SyntheticWeb Dec 17 '14 at 17:00
    
Doesn't image.blit draw the source (rotatedSurf1 in your case) into image? –  kazemakase Dec 17 '14 at 20:17
    
Thanks helped alot! –  SyntheticWeb Dec 18 '14 at 13:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.