Game Development Reference
In-Depth Information
let CollisionCategoryPlayer : UInt32 = 0x1 << 1
let CollisionCategoryPowerUpOrbs : UInt32 = 0x1 << 2
let CollisionCategoryBlackHoles : UInt32 = 0x1 << 3
Next, set the blackHoleNode.physicsBody 's categoryBitMask and colli-
sionBitMask , as shown in the following snippet. Add these lines directly before the
blackHoleNode is added to the foreground in the addBlackHolesToFore-
ground() method.
blackHoleNode.physicsBody!.categoryBitMask
= CollisionCategoryBlackHoles
blackHoleNode.physicsBody!.collisionBitMask = 0
After you have configured the blackHoleNode.physicsNody 's bit masks, you need
to add the CollisionCategoryBlackHoles to the player-
Node.physicsBody 's contactTestBitMask , as shown next. Find where the
playerNode.physicsBody 's contactTestBitMask is being set and modify it
to look like this line:
playerNode!.physicsBody!.contactTestBitMask =
CollisionCategoryPowerUpOrbs
| CollisionCategoryBlackHoles
There is one more change you need to make, and that is to modify the didBe-
ginContact() method so that it tests for the BLACK_HOLE node whenever nodes
come into contact with the playerNode . The simplest way to do this is to add an if
else condition to the current if statement in the method. This change is shown in the
following snippet:
if nodeB.name == "POWER_UP_ORB" {
impulseCount++
nodeB.removeFromParent()
}
else if nodeB.name == "BLACK_HOLE" {
playerNode!.physicsBody!.contactTestBitMask = 0
impulseCount = 0
}
Search WWH ::




Custom Search