Why are didBeginContact called multiple times?

前端 未结 6 1142
孤独总比滥情好
孤独总比滥情好 2020-11-27 22:18

In an iOS game that uses Sprite Kit along with the contact detection in Sprite Kit\'s build-in physics engine, I decrease the Hero\'s number lives by one each time he gets i

6条回答
  •  一生所求
    2020-11-27 22:45

    The reason why the didBeginContact is being fired multiple times is because you have multiple contact points happening on concave shapes.

    If you look at the picture below, you will see I have 2 sprites, a black star and a red rectangle. When the black star hits the red rectangle, it hits it on multiple points, circled in blue. Sprite Kit will then do a call for each line intersection, so that the developer can use the contactPoint variable for each of these contacts.

提交回复
热议问题