python - 如何使用 "actor.collidepoint(pos)"检查 pygame 中 Actor 之间的碰撞

标签 python pgzero

我对 pygame 很陌生,正在尝试制作一个游戏,其中 Actor 尝试击中 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方法来检测actor之间的碰撞:

if player.colliderect(gem):
    print("hit")

有关 Pygame 中碰撞的更多信息,请参阅问题的答案:

关于python - 如何使用 "actor.collidepoint(pos)"检查 pygame 中 Actor 之间的碰撞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65222519/

相关文章:

python - 如何根据 "If any observation in a particular column meets a condition, then True?"制作 Pandas 数据框列

python - 如何将向量连接到 numpy 矩阵的行中?

python - Python 的事件驱动 Web 框架

python - 同时从两个不同的脚本读取和写入同一个文件

python - Pygame 零 : TypeError: cannot create weak reference to 'NoneType' object

python - 名称 'Actor' 未定义

python - pygame - 如何完成游戏?

python - 使用 django 模板时出错