Game Development Reference
In-Depth Information
func addOrbsToForeground() {
let orbPlistPath =
NSBundle.mainBundle().pathForResource("orbs",
ofType: "plist")
let orbDataDictionary : NSDictionary? =
NSDictionary(contentsOfFile: orbPlistPath!)
if let positionDictionary = orbDataDictionary {
let positions
= positionDictionary.objectForKey("positions") as NSArray
for position in positions {
let orbNode = Orb(textureAtlas: textureAtlas)
let x = position.objectForKey("x") as CGFloat
let y = position.objectForKey("y") as CGFloat
orbNode.position = CGPointMake(x, y)
foregroundNode!.addChild(orbNode)
}
}
}
In the new
addOrbsToForeground()
method, you can see that it first loads the con-
tents of
orbs.plist
. After that, it grabs the array of positions out of the dictionary, and
finally it iterates over all of the positions, adding each
orbNode
to the
fore-
groundNode
at that position. Now you can change the number and layout of all the orb
nodes by simply changing the plist.
Make these changes to the
addOrbsToForeground()
method, and let's do the same
thing with the black holes. You have already copied the
blackholes.plist
file into
your project, so you can skip that step and move on to modifying the
addBlack-
HolesToForeground()
method to load the black hole positions from the plist. The
new
addBlackHolesToForeground()
method is 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])