It says rect argument is invalid
but when I give the same rect without a variable it works, here is the part of a code responsible for it
JavaScript
x
20
20
1
class Background:
2
def __init__(self, background):
3
self.background = background
4
self.endpoint = 5590
5
self.bx = 0
6
self.scrolling_right = False
7
self.scrolling_right = True
8
self.obstacleses = []
9
10
def obstacles(self):
11
self.obstacleses = pygame.Rect(300, 300, 20, 60)
12
print(self.obstacleses)
13
14
def surface(self):
15
screen.blit(self.background, (self.bx, 0))
16
screen.blit(templar1.image, templar1.pos)
17
screen.blit(Rogue.image, Rogue.pos)
18
pygame.draw.rect(screen, (255, 0, 0), self.obstacleses)
19
pygame.display.update()
20
I also tried self.obstacleses(0)
in pygame.draw.rect
but then i get list object is not callable
.
Advertisement
Answer
You have to draw the rectangles in a loop:
JavaScript
1
3
1
for obstacle in self.obstacleses:
2
pygame.draw.rect(screen, (255, 0, 0), obstacle)
3