Blazian444
Blazian444

Reputation: 129

Why is "get_rect()" not working for a list?

I am making a collision hitbox for my sprites but when I try to use get_rect this error occurs:

AttributeError: 'list' object has no attribute 'get_rect'

Does anyone know how to do this for a list of images?

scarn_up = [pygame.image.load('Michael Scarn Up 1.png'), pygame.image.load('Michael Scarn Up 2.png')]
scarn_up_rect = scarn_up.get_rect(topleft=(340, 150))

Upvotes: 1

Views: 428

Answers (1)

Akaisteph7
Akaisteph7

Reputation: 6486

Lists do not have a get_rect method. You want to do that on the pygame.Surface objects stored in your list. And you probably want to do it for each one of them and store their results in another list:

scarn_up = [pygame.image.load('Michael Scarn Up 1.png'), pygame.image.load('Michael Scarn Up 2.png')]
scarn_up_rect = [x.get_rect(topleft=(340, 150)) for x in scarn_up]

Upvotes: 1

Related Questions