TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Bubble Trouble issue

Forums > macOS

I just completed Pauls book Hacking with macOS up to Bubble Trouble (Swift UI addition). On the challenges I was able to find a solution to place "Game Over!" on the screen when all the bubbles are gone as expected. But expected the text to be blue as thats what I coded... Text remains white... Any clues to why this doesn't work? Heres a portion of the code:

  func pop(_ node: SKSpriteNode) {
        guard let index = bubbles.firstIndex(of: node) else { return }
        bubbles.remove(at: index)

        node.physicsBody = nil
        node.name = nil

        let fadeOut = SKAction.fadeOut(withDuration: 0.3)
        let scaleUp = SKAction.scale(by: 1.5, duration: 0.3)
        let group = SKAction.group([fadeOut, scaleUp])

        let sequence = SKAction.sequence([group, SKAction.removeFromParent()])
        node.run(sequence)

        run(SKAction.playSoundFileNamed("pop.wav", waitForCompletion: false))

        if bubbles.count == 0 {
            endGame = SKLabelNode(fontNamed: "Marker-Felt")
            endGame.color = NSColor.blue
            endGame.text = "Game Over!"
            endGame.fontSize = 128
            endGame.position = CGPoint(x: 400, y: 300)
            addChild(endGame)

            bubbleTimer?.invalidate()

        }

    }
}

3      

SKLabelNode has a fontColor property for the text color, not a color property. The default font color is white. You didn't set the font color for the label so you end up with white text.

The following code change should give you blue text:

endGame.fontColor = NSColor.blue

3      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.