I'm making a platformer in Pygame. One of the sprites I'm using is a flag, and I want to detect if the player collides with the flagpole (just like in Super Mario Bros). The problem is that the image is wider than the flagpole, because of the flag itself. I build the Rect for every sprite based on their image, just like so:
def initialize_rect(self, pos, correction = 0): self.rect = self.image.get_rect(topleft = pos)
Doing this, a collision is detected when the player touches the leftmost part of the image, which is a long way from the pole, so it looks terribly wrong.
I'm trying to figure out a way to change the collision box of the sprite, but nothing I try seems to work properly. I've tried the Rect.inflate() method, but that yielded no success. It shrinks the Rect from right to left, and if I then try to change the location of the Rect, the image changes its position too.
I could just make another sprite to detect collisions and somehow link it to the flag, but that would force me to change my design.
Is there a way to change the collision boxes of sprites directly in Pygame?