Game Development Reference
In-Depth Information
let moveAction
= SKAction.repeatActionForever(actionSequence)
let blackHolePlistPath =
NSBundle.mainBundle().pathForResource("blackholes",
ofType: "plist")
let blackHoleDataDictionary : NSDictionary? =
NSDictionary(contentsOfFile: blackHolePlistPath!)
if let positionDictionary = blackHoleDataDictionary {
let positions
= positionDictionary.objectForKey("positions") as NSArray
for position in positions {
let blackHoleNode = BlackHole(textureAtlas:
textureAtlas)
let x = position.objectForKey("x") as CGFloat
let y = position.objectForKey("y") as CGFloat
blackHoleNode.position = CGPointMake(x, y)
blackHoleNode.runAction(moveAction)
foregroundNode!.addChild(blackHoleNode)
}
}
}
As you look over the changes to the addBlackHolesToForeground() method, you
will see that it now, just like the addOrbsToForeground() method, reads all of the
black hole node positions from the plist and then adds each of the blackHoleNode s at
those read-in positions. Make this change and run your game again. You will see no dif-
ference, but now people with little to no development experience can completely change
the game.
Keeping Your Node Tree Pruned
The final best practice to implement in the SuperSpaceMan game is to remove all
SKNode s that have dropped off the bottom of the viewable scene. Removing unnecessary
nodes from your games will improve the overall performance of node tree rendering and
reduce the amount of memory used to hold all of the nodes in your node tree.
A simple way to remove unnecessary nodes from GameScene is to create a method that
will remove all nodes with a given name that are one scene length below the player-
Search WWH ::




Custom Search