UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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 RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.