Python Forum
[PyGame] Rotation Problem in PyGame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Rotation Problem in PyGame
#1
I tried to recreate Flappy Bird using pygame and everything works properly except for the rotation of the Flappy Bird.

The rotated image increases the size of the rect of sprite which it makes detecting the collision of the bird with the pipes difficult.
Here is my rotation function of the bird sprite:

def rotation(self, dt):
        """
            Rotates the bird as per its position
        :param dt: for counting frames
        :return: None
        """
        if self.isJump and not self.isUp:
            old_center = self.rect.center
            for i in range(3):
                self.group_images[i] = self.rotated_group_images[i]
            self.image = self.group_images[self.image_index]
            self.rect = self.image.get_rect()
            self.rect.center = old_center
            self.isUp, self.isDown = True, False

        if self.isUp and self.isJump:
            self.jump_height = self.rect.y

        if not self.isJump and not self.isDown:
            if self.rect.y > self.jump_height:
                if self.rotated >= self.max_rotation:
                    self.rotation_time += dt
                    if self.rotation_time >= self.rotation_animation_time:
                        self.isUp = False
                        old_center = self.rect.center
                        for i in range(3):
                            self.group_images[i] = pygame.transform.rotate(self.group_images[i], self.rotate)
                        self.image = self.group_images[self.image_index]
                        self.rect = self.image.get_rect()
                        self.rect.center = old_center
                        self.rotated += self.rotate
                        if self.rotated == self.max_rotation:
                            self.isDown = True
                            self.rotated = 0
Here is what the game looks like. I have drawn the rect of the sprite to show its size:

[Image: ETrlk4p]
[Image: Hsh1oqY]
[Image: oVLTK5q]

I have changed the new rect with the old rect's center but still its size is getting bigger.

Here is a link to my project:
https://github.com/pranav-28/FlappyBird
Reply
#2
You must rotate from original image. Otherwise there will be side effects. Like image will degrade the more you rotate it.
You can use pygame mask. Otherwise keep original rect for collision.
99 percent of computer problems exists between chair and keyboard.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Pygame display problem video game Paul_Maillet 1 614 Feb-20-2024, 07:50 PM
Last Post: Bronjer
  Problem with pygame.event.clear qq12346 1 2,059 Oct-05-2023, 08:39 AM
Last Post: patriciainman
  pygame double jump problem Yegor123 3 2,508 May-02-2023, 09:34 PM
Last Post: sudoku6
  [PyGame] Sprite image rotation problem XavierPlatinum 4 2,264 Jul-25-2022, 01:31 PM
Last Post: Ruslan8819
  (HELP GREATLY APPRECIATED) New user- Huge Pygame Installation Problem! Jbomb 1 2,782 Jan-12-2021, 07:32 PM
Last Post: MK_CodingSpace
  problem with pygame Aladdin 3 4,145 Jun-25-2020, 01:41 PM
Last Post: Aladdin
  angle of rotation berckut72 4 2,957 Apr-27-2020, 04:55 PM
Last Post: berckut72
  Problem with music - Pygame.error GaseBall 1 3,150 Nov-28-2019, 07:46 PM
Last Post: SheeppOSU
  My Pygame Project's Problem **huh** osmanb06 2 3,613 Nov-06-2018, 09:27 AM
Last Post: osmanb06
  Coding problem in a Pygame Sghet 4 7,961 Aug-13-2018, 05:39 PM
Last Post: MTGReen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020