The collision currently works and I can play my game for a while but after about 50 or so enemy ships are destroyed I get the error EXC_BREAKPOINT (code=1, subcode=0x1003f42cc)
I am getting it on this line of code
projectileDidCollideWithEnemy(firstBody.node as SKSpriteNode, enemy: secondBody.node as SKSpriteNode)
Here are the bits of code that I believe are effecting it and that the breakpoint leads to.
func didBeginContact(contact: SKPhysicsContact) {
var firstBody: SKPhysicsBody
var secondBody: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
firstBody = contact.bodyA
secondBody = contact.bodyB
}
else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
if ((firstBody.categoryBitMask & PhysicsCategory.Enemy != 0) &&
(secondBody.categoryBitMask & PhysicsCategory.Projectile != 0)) {
projectileDidCollideWithEnemy(firstBody.node as SKSpriteNode, enemy: secondBody.node as SKSpriteNode)
}
And here is the func that gets called
func projectileDidCollideWithEnemy(projectile:SKSpriteNode, enemy:SKSpriteNode) {
projectile.removeFromParent()
enemy.removeFromParent()
score++
scorelabel.text = String(score)
}