iosswiftsprite-kitsklabelnode

SKLabelNode not showing up


I am trying to get an SKLabelNode to show up on my screen, but it doesn't show. Here is my code...

 override func didMoveToView(view: SKView) {

    let textLabel = SKLabelNode(fontNamed: "Avenir-Black")

    textLabel.text? = "HI THERE"
    //textLabel.position = CGPoint(x: frame.midX, y: frame.midY)
    textLabel.horizontalAlignmentMode = .Center
    textLabel.verticalAlignmentMode = .Center
    textLabel.fontSize = 100
    textLabel.zPosition = 2
    textLabel.color = UIColor.whiteColor()
    textLabel.name = textLabel.name
    print("flkjsfhdj")

    self.addChild(textLabel) }

What am I doing wrong?


Solution

  • The code should be written as

    textLabel.text = "Hi there"
    

    and not

    textLabel.text? = "Hi there"