Why are didBeginContact called multiple times?

前端 未结 6 1178
孤独总比滥情好
孤独总比滥情好 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:54

    I figured out easy solution:

    Just change either body's categoryBitMask value to 0 or non-used value right after it detected contact.

    For example:

    if (firstBody.categoryBitMask == padCategory && secondBody.categoryBitMask == colorBallCategory) {
    
          secondBody.categoryBitMask = 0;
    
          // DO OTHER THING HERE
    
    }
    

提交回复
热议问题