I understand how the below DidBeginConact function works, but how do you detect which categories make contact when you have multiple colored bars (in the example code) or a friend category and enemy category when an enemy overlaps a friend or two enemies overlap and a projectile category intersects both at the same time?
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 == RedBallCategory &&
secondBody.categoryBitMask == GreenBarCategory {
(secondBody.node!.removeFromParent())
score++
scoreLabel.text = "\(score)"
} else if firstBody.categoryBitMask == GreenBallCategory &&
secondBody.categoryBitMask == RedBarCategory {
(secondBody.node!.removeFromParent())
score++
scoreLabel.text = "\(score)"
}
I've tried so many different combinations I can't keep them all straight or remember what I've tried and what I haven't.
Thanks in advance for help and suggestions in this.