Game Development Reference
In-Depth Information
name = "BLACK_HOLE"
runAction(rotateAction)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Once you have the new BlackHole class in place, you can then change the ad-
dBlackHolesToForeground() method to look like the following simplified meth-
od:
func addBlackHolesToForeground() {
var moveLeftAction = SKAction.moveToX(0.0, duration:
2.0)
var moveRightAction = SKAction.moveToX(self.size.width,
duration: 2.0)
var actionSequence = SKAction.sequence([moveLeftAction,
moveRightAction])
var moveAction
= SKAction.repeatActionForever(actionSequence)
for i in 1...10 {
// new black hole usage code
var blackHoleNode = BlackHole()
blackHoleNode.position
= CGPointMake(self.size.width - 80.0, 600.0 * CGFloat(i))
blackHoleNode.runAction(moveAction)
foregroundNode!.addChild(blackHoleNode)
}
}
Moving these nodes into their own classes makes it a lot easier to reuse each of the nodes,
and it also cleans up the GameScene .
Reusing Textures
The next best practice you are going to see is how you can use a single instance of an
SKTextureAtlas to load all of the sprite images and then just reuse the atlas when set-
Search WWH ::




Custom Search