0

In my didEndContact: method I increment a "currentScore".

For some reason, didEndContact: is not being called, and hence the "currentScore" is not being incremented. Any ideas why or what I should be looking for to debug this?

func didEndContact(contact: SKPhysicsContact) {
    guard goal!.barEnabled else { return }
    score += 1
}

Here is related code, let me know if I can add any other helpful details too:

var barEnabled:Bool {
    set {
        bar?.physicsBody?.collisionBitMask = newValue ? CollisionMask.Puck : CollisionMask.None
        bar?.physicsBody?.categoryBitMask = newValue ? CollisionMask.Goal : CollisionMask.None
    }
    get {
        return bar?.physicsBody?.collisionBitMask == CollisionMask.Puck
    }
}
SRMR
  • 3,064
  • 6
  • 31
  • 59
  • are you removing the sprite from the scene before didEndContact happens? Because it will not get called then – Knight0fDragon Oct 24 '16 at 14:24
  • @Knight0fDragon yeah I checked on that because of this: http://stackoverflow.com/questions/29331799/spritekit-didbegincontact-called-but-not-didendcontact , but thanks for double checking with me – SRMR Oct 24 '16 at 15:04

1 Answers1

1

In order to detect collisions, you'll have to set the contactTestBitMask of the physicsBody.

The contactTestBitMask of a physicsBodys and the categoryBitMask of another physicsBodys have to be not 0 when an binary AND operation is applied to the 2 integers for the detection to trigger.

In case you have not already, make sure that the physicsWorld.contactDelegate of the scene is set to self and that it implements the SKPhysicsContactDelegate.

Christoph
  • 702
  • 6
  • 16
  • Double checked that I have `physicsWorld.contactDelegate = self` and also that the Scene implements `SKPhysicsContactDelegate`, so that looks good, and thanks for explaining the detecting collisions just so I could check that I was doing the bit mask parts too. – SRMR Oct 20 '16 at 15:41
  • I need a little bit more context in order to figure out why it's still not working. – Christoph Oct 22 '16 at 14:08
  • I did get it working now, so I marked the answer but forgot to add a comment. Thanks a lot! – SRMR Oct 22 '16 at 15:54