I'm very new to pygame and am trying to make a game where the actor try's to hit the gem, but I cant figure out how to use the "actor.collidepoint(pos)" function for that! Answers are greatly appreciated!
Asked
Active
Viewed 617 times
2
-
1You can look at [this](https://stackoverflow.com/questions/58717367/how-does-the-collidepoint-function-in-pygame-work) – Aven Desta Jan 28 '21 at 16:48
1 Answers
2
See Actor:
Actors have all the same attributes and methods as
Rect
, including methods like .colliderect() which can be used to test whether two actors have collided.
Supposing you have to Actor
objects:
player = Actor("player_image.png")
gem = Actor("gem_image.png")
Use colliderect
method to detect the collision between the actors:
if player.colliderect(gem):
print("hit")
For more information about collisions in Pygame, see the answers to the questions:

Rabbid76
- 202,892
- 27
- 131
- 174