如何使用 "actor.collidepoint(pos)" 检查 pygame 中的演员之间的碰撞
How can I check collisions between actors in pygame using "actor.collidepoint(pos)"
我是 pygame 的新手,我正在尝试制作一款游戏,让演员尝试击中 gem,但我不知道如何使用“actor.collidepoint(pos)" 的功能!非常感谢回答!
见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.
假设您必须 Actor
个对象:
player = Actor("player_image.png")
gem = Actor("gem_image.png")
使用colliderect
方法检测演员之间的碰撞:
if player.colliderect(gem):
print("hit")
有关 Pygame 中冲突的更多信息,请参阅问题的答案:
- How do I detect collision in pygame?
我是 pygame 的新手,我正在尝试制作一款游戏,让演员尝试击中 gem,但我不知道如何使用“actor.collidepoint(pos)" 的功能!非常感谢回答!
见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.
假设您必须 Actor
个对象:
player = Actor("player_image.png")
gem = Actor("gem_image.png")
使用colliderect
方法检测演员之间的碰撞:
if player.colliderect(gem):
print("hit")
有关 Pygame 中冲突的更多信息,请参阅问题的答案:
- How do I detect collision in pygame?