Search code examples
swiftsprite-kitsklabelnode

scoreLabel.text making game pause


I'm setting a label

let scoreLabel = SKLabelNode(fontNamed: "Edit Undo Line BRK")

in a function

func increaseScoreBy(increment: Int) {
    score += increment
    scoreLabel.text = "Score: 100"
    scoreLabel.removeAllActions()
    scoreLabel.runAction(scoreFlashAction)
}

and if I comment out the scoreLabel.text = "Score: 100" then it will run perfectly but the score obviously won't update. originally I had it \(score) but I changed it to static text to see if that was the issue. any ideas on why this would act like this?

there is one thing, if its \(score) instead of 100 it will pause (temporarily freeze) the game every time the score updates, if its hard coded, it only freezes the first time.

update

Initialization of the scoreLabel in the game setup

scoreLabel.fontsize = 50
scoreLabel.text = "Score: 0"
scoreLabel.name = "scoreLabel"
scoreLabel.verticalAlignmentMode = .Center
scoreLabel.position = CGPoint( x: size.width / 2, y: size.height - scoreLabel.frame.size.height + 3)
hudLayerNode.addChild(scoreLabel)

scoreFlashAction = SKAction.sequence([SKAction.scaleTo(1.5, duration: 0.1), SKAction.scleTo(1.0, duration: 0.1)])
scoreLabel.runAction(SKAction.repeatAction(scoreFlashAction, count: 20))

update

It is definitely the font type some how. I removed the fontName and just made a regular label and no issues, but of course the font is wrong.


Solution

  • some one deleted the answer so here it is again

    Thanks to

    How to cache or preload SKLabelNode font?

    for a hint at what was going on. While the name was correct, I had not "added" the font to the app. to do this click on your targets and the info tab. create a new key of "Fonts provided by application" under the customer ios target properties. expand it and add the font name as the value of the item. don't forget to copy the ttf into your application folders and make sure copy and target are both selected when you do.