Pygame碰撞

时间:2011-11-29 04:37:03

标签: python collision-detection pygame sprite

如何使用pygame.sprite.collide_rect

我想制作一个游戏,如果女孩在冰上,她slide,当她在地上(这将是另一个sprite)时,她不会slide。我打算使用pygame中的碰撞检测,但我不确定如何。

有人可以帮帮我吗?

非常感谢

2 个答案:

答案 0 :(得分:1)

你能发布你的代码吗?

从我收集的内容来看,你想要的是这样的:

if pygame.girl.colliderect(ice.rect):
     girl.slide()
elif pygame.girl.colliderect(ground.rect):
     girl.notslide()

答案 1 :(得分:0)

有多种方法可以在pygame中检测碰撞。包括rect,精灵组等......为了找到一种特定的碰撞检测方法,只需看看你正在使用的代码。但是使用简单的精灵和矩形你可以使用:

if pygame.sprite.collide_rect(girl_sprite, ice):
   slide()
else :
   continue_game()