here is what I have until now, I have draw the rect to keep a track of it, here is the code:
class Personagem(pygame.sprite.Sprite):
def __init__(self,x,y):
super().__init__()
self.imagem = pygame.image.load('sprites/frente-parado.bmp')
self.rect = self.imagem.get_rect()
self.rect.height = 20
self.rect.width = 20
self.rect.centerx = x
self.rect.centery = y
self.velocidade_x = 0
self.velocidade_y = 0
I have been looking at similar questions here, a have tried create another rect that starts at the bottom left of the original but then I cant collide it because the sprite ended up with two rects
I appreciate any answer, sorry for bad english
To center the rect of a sprite in the image, you can use the center attribute of the rect instead of centerx and centery. Here's an updated version of your code that centers the rect:
In this version, the center attribute of the rect is set to the tuple (x, y), which will center the rect in the image. Note that I've also switched the order of the width and height attributes, as it's recommended to set the width before the height when working with pygame.