[Solved] Have a collision only detected once


Yep – this happens. The way to handle it (you can’t get sprite-kit to NOT call didBegin multiple times in some circumstances) is to make sure that your contact code accommodates this and that handling the contract multiple times does not cause a problem (such as adding to the score multiple times, removing multiple lives, trying to access a node or physicsBody that has been removed etc).

There is a discussion here: Sprite-Kit registering multiple collisions for single contact

Some things you can do include:

  • If you remove a node that is contacted, check for it being nil before
    you remove it (for the duplicate contacts)
  • Add the node to a set and then remove all the nodes in the set in
    didFinishUpdate
  • Add an ‘inactive’ flag’ to the node’s userData
  • Make the node a subclass of SKSpriteNode and add an inactive property
  • Etc etc.

0

solved Have a collision only detected once