sprite-kit SKNode Collision


The determinants of Sprite Kit collision and contact event processing are the relationship settings, created by you, of categoryBitMask, collisionBitMask and contactTestBitMask for each of your interacting object types. By rationally setting these in service of your desired outcomes from contacts and collisions, you determine which types can collide and inform of contacts with others, and avoid undesired collision, contact and physics processing overhead.

For each type of 'entity' you can set all three:

  1. categoryBitMask : a category specific to this type of node
  2. collisionBitMask : a collision differentiator, can be different from above
  3. contactTestBitMask : a contact differentiator, can be different from both above

The general steps to implement collisions & contacts are:

  1. set physic body size, shape and (sometimes) mass
  2. add necessary BitMasks for your node type from category, collision and contact above
  3. set scene as a contact delegate enabling it to check and inform of collisions and contacts
  4. implement contact handlers and any other pertinent logic for physics events