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!
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: