SKLabelNode text disappears using iOS 7.1

I wrote a function called updateLabel to count my collected coins over time. I am calling this function with NSTimer to get the counting effect.

Everything works fine with iOS 8, but as soon as I call the function using iOS 7.1, my label just goes blank ... If I print the Label.text I get the number I want, but it just doesn't appear. Even the "coinSound" sound works.

scoreLabel = SKLabelNode()
scoreLabel.text = "0"
self.addChild(scoreLabel)           // shows up and works with "0"

self.timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self.self, selector: "updateLabel", userInfo: nil, repeats: true)

func updateLabel() {

    var score:Int = coinsCollected
    var current:Int = self.scoreLabel.text.toInt()!

    if (current < score) {

        current += 1
        scoreLabel.text = String(current)
        println("current: \(current) , labelText: \(scoreLabel.text)")    
    } else {



thanks for the help


source to share

1 answer

Is the label ever rendered or is it just empty when you try to update it?

If this is the first case, then it may be that the shortcut is not displayed at all, and not only does not update the text. For example, it could be behind another element, when you don't expect it, it could be done somewhere you don't expect, it could be rendered with zero alpha or a color that matches the background (white on for example white), or it cannot find the information it needs to create the glyphs (i.e. you can use a font that is not available on this system).

If this is the latter case, it might be a problem with how you compute the text. I notice that you are doing something a little weird - you get the "current" value by taking the Int value of the current text, adding it, and then setting the text back. The problem with this approach is that if you ever have a non-integer value as text in that field, then you will break that field forever. A better approach would be to store the Int variable, increment it, and then set the field text to that.

You can test between these cases by simply setting that field text to just "1" or something to see if it appears. If you can display a static text element, then you can go to dynamic display. But if the static text is not displayed, then that means the timer based dynamic code has nothing to do with the problem.

You can check that you are using a valid font name. For example, "Arial" is not a font name, you will have to use "ArialMT". Make sure you are using the actual font name.



All Articles