在swift中使用动画更改字体/标签大小

时间:2015-01-24 03:22:38

标签: animation swift resize label

我来自代码后,当游戏代码运行时增加我的标签大小....这就是我现在所拥有的

if gameOver == 0 {
            movingObjects.speed = 0
            gameOver = 1
            movingObjects.removeAllChildren()// Remove all enemies
            gameOverLabel.fontSize = 43
            gameOverLabel.text = "Tap to retry!"
            gameOverLabel.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame)*1.5)
            labelHolder.addChild(gameOverLabel)
            gameOverLabel.zPosition = 9



            var pauseScore = SKAction.waitForDuration(0.4)
            var moveScore = SKAction.moveToY(CGRectGetMidY(self.frame)*1.2, duration: 0.8)
            var resizeScore = SKAction.runBlock({
            self.scoreLabel.fontSize = 150
            })
            var scoreEndSequence = SKAction.sequence([pauseScore, moveScore, resizeScore])
            scoreLabel.runAction(scoreEndSequence)


            if (UInt(score) > UInt(hScore as NSNumber)) {
                NSUserDefaults.standardUserDefaults().setObject(score, forKey: "highscore")
                println("Highscore Saved")
            } else {
                println("Highscore Not Saved")
            }

我希望scoreLabel也能变得更大......现在我现在所做的就是这样做但它只是跳到150我希望它能够动画

2 个答案:

答案 0 :(得分:1)

似乎属性fontSize不可动画 要解决此问题,请将持有人更改为视图对象

答案 1 :(得分:0)

您可以像这样设置节点大小:

var grow = SKAction.scaleTo(10, duration: 0.5)

但是如果你使用SKLabelNode执行此操作,如果文本太大,文本将看起来很糟糕。节点大小更改时未再次呈现的文本。