0

Error in Line 105

My code:-

    def rotate(self):
    self.rotate_ticks -= 1
    if self.rotate_ticks == 0:
        self.angle = (self.angle + self.angular_velocity) % 360
        orig_rect = self.image.get_rect()
        rot_image = pygame.transform.rotate(self.image, self.angle)
        rot_rect = orig_rect.copy()
        rot_rect.center = rot_image.get_rect().center
        rot_image = rot_image.subsurface(rot_rect).copy()
        self.image = rot_image
        self.rotate_ticks = 3

I have written the above code for rotating asteroids in my game Space Shooter which I have made using Python's pygame.

Please help me in fixing this error, I have tried many times to do changes to the code and even I changed the dimensions of my assets, still getting this error. And when I run this game, it crashes after few seconds.

  • It is a bad idea to rotate the original image progressively. See [How do I rotate an image around its center using Pygame?](https://stackoverflow.com/questions/4183208/how-do-i-rotate-an-image-around-its-center-using-pygame/54714144#54714144) – Rabbid76 Jun 12 '20 at 05:18
  • @Rabbid76 Can you please reopen this Q, I am not able to figure out the error in my code that's why I asked. I accept that those answers are very well written but I wanted to know what's wrong with my code. – Bhanuteja G Jun 12 '20 at 05:58
  • Of course I've read your question. Your general approach is wrong, because your image will be distorted. The best help I can give you is to show you the answers to the referenced questions. Anyway, [`subsurface()`](https://www.pygame.org/docs/ref/surface.html#pygame.Surface.subsurface) doesn't create a copy of a part of a surface, it creates a new surface that references its parent. – Rabbid76 Jun 12 '20 at 06:09

0 Answers0