SKLabelNode设备之间的自定义大小

时间:2015-08-03 11:06:03

标签: swift sprite-kit sklabelnode

我正在使用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])))

1 个答案:

答案 0 :(得分:2)

尝试替换

scoreLabel.fontSize = 15

scoreLabel.fontSize = UIDevice.currentDevice().userInterfaceIdiom == .Pad ? 30 : 15
相关问题