【发布时间】:2015-08-03 11:06:03
【问题描述】:
我正在使用 SKLabelNode 来显示通用游戏的分数。字体大小对于 iPhone 来说是完美的,但对于 iPad 来说自然需要更大。我想知道是否有任何方法可以更改 iPad 的字体大小?我在 didMoveToView 中试过这个:(可能完全错误,但我唯一能想到的)
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
scoreLabel.fontSize = 45 }
这不起作用。有任何想法吗?? 注意:如果这有什么不同,我使用的是自定义字体而不是苹果字体。
let scoreLabel = SKLabelNode(fontNamed: "DS Digital")
scoreLabel.position = CGPoint(x: size.width * 0.07, y: size.height * 0.9)
scoreLabel.text = "0"
scoreLabel.fontSize = 15
addChild(scoreLabel)
scoreLabel.zPosition = 3
let waitScore = SKAction.waitForDuration(1.0) //add score every second
let incrementScore = SKAction.runBlock ({
++self.score
self.scoreLabel.text = "\(self.score)"}) //update score label with score
self.runAction(SKAction.repeatActionForever(SKAction.sequence([waitScore,incrementScore])))
【问题讨论】:
-
你能粘贴这个
SKLabelNode的完整代码吗?请从创建到添加到场景中。 -
我已经更新了我的问题。
标签: swift sprite-kit sklabelnode