Python Forum
[PyGame] Sprite image rotation problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Sprite image rotation problem
#1
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.
Reply
#2
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)
XavierPlatinum and BashBedlam like this post
99 percent of computer problems exists between chair and keyboard.
Reply
#3
(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.
Reply
#4
99 percent of all computer issues occur between the chair and the keyboard. gmail
Reply
#5
thank you for your answers
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  angle of rotation berckut72 4 2,957 Apr-27-2020, 04:55 PM
Last Post: berckut72
  [PyGame] Sprite image.get_rect() moves sprite to 0, 0 michael1789 2 4,552 Dec-13-2019, 08:37 PM
Last Post: michael1789
  [PyGame] Rotation Problem in PyGame thunderbird028 1 2,659 Nov-14-2019, 06:49 AM
Last Post: Windspar
  Sprite not rendering Clunk_Head 2 2,095 Oct-03-2019, 11:27 AM
Last Post: Clunk_Head
  Need help making a sprite GalaxyCoyote 4 3,186 Aug-11-2019, 09:12 PM
Last Post: metulburr
  moving a sprite pfaber11 3 2,548 May-15-2019, 12:52 PM
Last Post: pfaber11
  [PyGame] Need Help With Sprite ghost0fkarma 2 3,253 Jan-09-2018, 02:14 PM
Last Post: ghost0fkarma
  [pyGame] Load Image, Problem Found ! JamieVanCadsand 2 8,688 Sep-29-2017, 06:26 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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