我尝试从SKLabelNode
读取文字。但是我总是得到“在解开一个Optional值时意外地发现nil”。但是因为我初始化Node并添加了Text,所以不能有零值。守则如下。有谁知道为什么?
powerStar = SKLabelNode(fontNamed: "ChalkboardSE-Bold")
powerStar.fontSize = 30
powerStar.fontColor = SKColor.yellowColor()
powerStar.position = CGPoint(x: CGFloat(self.OFFSET + self.COUNTOFFSET + (self.HORIZONTALSPACE * self.activePowers)), y: self.vertivalAlignment)
powerStar.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Left
powerStar.text = String(format: ": %d", 10)
self.addChild(powerStar)
...
func update(model:Model){
NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("updateAllHuds"), userInfo: nil, repeats: true)
}
...
else if self.starActive{
_ = Int(self.powerStar.text!)
}