How do I create collision detections for my bouncing balls?

后端 未结 7 1247
星月不相逢
星月不相逢 2021-02-04 18:13

I have coded an animation (in python) for three beach balls to bounce around a screen. I now wish to have them all collide and be able to bounce off each other. I would really a

7条回答
  •  星月不相逢
    2021-02-04 18:34

    First you need to check collision with rect.colliderect(other_rect)

    after that if they are colliding, you can check pixel perfect collision. So you don't mess with object's radius or shape.

    For pixel perfect collision checking, I use Masks: Make both mask objects with mask.from_surface, then put them to Mask.overlap function.

提交回复
热议问题