Game Development Reference
In-Depth Information
The first part you will need to do is to make one variable to hold the SKLabelNode object.
Since you will be using the time interval from NSDate , you will need to create an NSNum-
berFormatter .
var timeNode: SKLabelNode!
var livesLeftNode: SKLabelNode!
var lives:Int = 3
var timerFormat: NSNumberFormatter!
Now that you have some variables, you will need to initialize them before you use them.
Listing 15-1 shows you the overridden init(size: CGSize) function.
Listing 15-1 . GameView.init
override init(size: CGSize) {
super.init(size: size)
self.anchorPoint = CGPointMake(0.5, 0.5)
self.scaleMode = .ResizeFill
self.timeNode = SKLabelNode(fontNamed:
"AvenirNext-Bold")
self.timeNode.text = "Time: 0.0"
self.timeNode.fontColor = SKColor.redColor()
self.timeNode.horizontalAlignmentMode = .Left
self.timeNode.verticalAlignmentMode = .Bottom
self.timeNode.position = CGPointMake(-size.width/2
+ 20, size.height/2 - 40)
self.timeNode.name = "timer"
self.addChild(timeNode)
self.timerFormat = NSNumberFormatter()
self.timerFormat.numberStyle = .DecimalStyle
self.timerFormat.minimumFractionDigits = 1
self.timerFormat.maximumFractionDigits = 1
}
In this initializer function, you will do a few things that you should stop and look at before
moving on. This first part is creating the SKLabelNode that will be used to show the timer
counting up. You can change the font and color if you want something that would suit
your needs better; however, the red with Copperplate looks pretty decent in this game.
Search WWH ::




Custom Search