Pygame: Collision by Sides of Sprite

前端 未结 4 1410
春和景丽
春和景丽 2020-11-30 12:07

Is there a way in pygame to look for a collision between the a particular side of a sprite and a particular side of another sprite in pygame? For example, if the top of spri

4条回答
  •  旧巷少年郎
    2020-11-30 12:33

    For objectA give the object this method:

    def is_collided_with(self, sprite): return self.rect.colliderect(sprite.rect)

    This return statement returns either True or False

    then in the main loop for collisions just do: if objectA.is_collided_with(ObjectB): Collision happened!

提交回复
热议问题