1

The title basically explain it all. Here's the code for the pygame.draw.rect:

stand = pygame.draw.rect(screen, green, (spike_x + 900, 400 - player_y + 476, 500, 500), border_radius=15)

I want the stand to be able to collide with the player. The player is using a rect collision box:

player_collision = player.get_rect(topleft=(player_x, player_y))

I've tried to use if player_collsion.collidepoint(stand):, but it doesn't work. When I try that, it says TypeError: argument must contain two numbers

Duck Duck
  • 159
  • 6
  • When you looked into the documentation for `collidepoint` what did they they tell you the arguments were? Can you somehow get the two numbers out of the `stand` object? – RufusVS Dec 12 '20 at 20:55
  • 1
    ... try `if player_collsion.colliderect(stand):`, compare [`collidepoint()`](https://www.pygame.org/docs/ref/rect.html#pygame.Rect.collidepoint) and [`colliderect()`](https://www.pygame.org/docs/ref/rect.html#pygame.Rect.colliderect) – Rabbid76 Dec 12 '20 at 20:56

1 Answers1

2

You have to use colliderect() rather than collidepoint(). collidepoint is used to compare a rectangle and a point, colliderect is used to compare 2 rectangles:

if player_collsion.collidepoint(stand):

if player_collsion.colliderect(stand):
Rabbid76
  • 202,892
  • 27
  • 131
  • 174