Game Development Reference
In-Depth Information
tional. I think the game needs several black holes to make it more difficult to play. Take a
look at the new addBlackHolesToForeground() method shown here:
func addBlackHolesToForeground() {
let moveLeftAction = SKAction.moveToX(0.0, duration:
2.0)
let moveRightAction = SKAction.moveToX(size.width,
duration: 2.0)
let actionSequence = SKAction.sequence([moveLeftAction,
moveRightAction])
let moveAction
= SKAction.repeatActionForever(actionSequence)
for i in 1...10 {
var blackHoleNode = SKSpriteNode(imageNamed:
"BlackHole0")
blackHoleNode.position
= CGPointMake(self.size.width - 80.0, 600.0 * CGFloat(i))
blackHoleNode.physicsBody
= SKPhysicsBody(circleOfRadius: blackHoleNode.size.width
/ 2)
blackHoleNode.physicsBody!.dynamic = false
blackHoleNode.physicsBody!.categoryBitMask
= CollisionCategoryBlackHoles
blackHoleNode.physicsBody!.collisionBitMask = 0
blackHoleNode.name = "BLACK_HOLE"
blackHoleNode.runAction(moveAction)
self.foregroundNode!.addChild(blackHoleNode)
}
}
As you look at this code, you will notice it iterates over a for loop 10 times, adding an-
other black hole every 600 points above the previous black hole. As it does so, it tells each
new node to run the moveAction created earlier. To see this change in action, use this
code to replace the current addBlackHolesToForeground() method and run the
app. When you run the app this time, you will see additional black holes going up the
length of the scene.
Search WWH ::




Custom Search