Python Forum
[PyGame] Sprite image rotation problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: [PyGame] Sprite image rotation problem (/thread-37611.html)



Sprite image rotation problem - XavierPlatinum - Jun-30-2022

I'm likely just blind, but I can't find the reason my pygame sprite image (which is just a pygame.Surface) is a solid, filled square that grows and shrinks rather than rotates. Rather, it is rotating and the rect is growing and shrinking as it rotates, which is good, but I only see a box that changes size. It seems to rotate the the image then fills the resulting rect with the image's fill colour.

        self.original_img = pg.Surface((50, 50))
        self.original_img.fill((100, 55, 10))
        self.rect = self.original_img.get_rect()
        self.image = self.original_img

####   then....

        self.image = pg.transform.rotate(self.original_img, self.rot)
        self.rect = self.image.get_rect()

#### then....
         screen.blit(self.player.image, self.player.rect)


Do I have a typo? There aren't and extra fill()s or anything else that I can see impacting the image. I missed the focused frustration of coding, but this is pretty simple for me to be stuck on lol.

Thanks in advance.


RE: Sprite image rotation problem - Windspar - Jul-01-2022

Its because you didn't use and alpha.
self.original_img = pg.Surface((50, 50), pygame.SRCALPHA)
If using image. Make sure you convert_alpha() on it.

You also might want to keep it in center.
self.rect = self.image.get_rect(center=self.rect.center)



RE: Sprite image rotation problem - XavierPlatinum - Jul-02-2022

(Jul-01-2022, 04:27 AM)Windspar Wrote: Its because you didn't use and alpha.
self.original_img = pg.Surface((50, 50), pygame.SRCALPHA)
If using image. Make sure you convert_alpha() on it.

You also might want to keep it in center.
self.rect = self.image.get_rect(center=self.rect.center)


Thank you very much, I appreciate your time. Gee, I've really forgot more than I thought during my away time.

For the centering I have a player.pos I center to. If memory serves, I used to do that for use in animation later. But for now I get to frustrate myself with movement and shooting! haha. Coding is fun.


RE: Sprite image rotation problem - unawareenormousy - Jul-19-2022

99 percent of all computer issues occur between the chair and the keyboard. gmail


RE: Sprite image rotation problem - Ruslan8819 - Jul-25-2022

thank you for your answers