Pygame 碰撞检测
我该如何使用 pygame.sprite.collide_rect
呢?
我想做一个游戏,里面有个女孩在冰上会 滑动
,而在地面上(地面会是另一个 sprite
)她就不会 滑动
。我打算用 pygame 的碰撞检测功能,但我不太确定该怎么做。
有人能帮我吗?
非常感谢!
2 个回答
0
在pygame中,有很多种方法可以检测碰撞,比如使用矩形、精灵组等等。要找到一种特定的碰撞检测方法,其实就是看看你正在使用的代码。不过,如果你只是想用一个简单的精灵和矩形来检测碰撞,你可以直接使用:
if pygame.sprite.collide_rect(girl_sprite, ice):
slide()
else :
continue_game()
2
你能把你的代码发出来吗?
根据我理解的情况,你想要的东西大概是这样的:
if pygame.girl.colliderect(ice.rect):
girl.slide()
elif pygame.girl.colliderect(ground.rect):
girl.notslide()