1

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?

  • my guess is you have a weird scalemode going on, your label is in the bottom left corner of the screen – Knight0fDragon Jul 01 '16 at 16:25
  • @Knight0fDragonDo you know how I can fix that? – Michael Geddes Jul 01 '16 at 16:30
  • well first you need to check your scale mode, to start I would use `.Fill` (I think the default is different). Then use `let point = CGPoint(x:CGRectGetMidX(frame), y:CGRectGetMidY(frame))` and set the label position to it. `textLabel.position = point` – Knight0fDragon Jul 01 '16 at 16:34

4 Answers4

1

You just need to give your label a position:

textLabel.position = CGPoint(x:500, y:200)
squarehippo10
  • 1,855
  • 1
  • 15
  • 45
1

The code should be written as

textLabel.text = "Hi there"

and not

textLabel.text? = "Hi there"
1

I had same problem.

My solution is like this...

not textLabel.color = UIColor.white,

but textLabel.fontColor = UIColor.white

pps
  • 11
  • 1
0

Also in addition to the fontColor as pps mentioned, the fontSize should be over maybe 20 depending on the device it may be too thin to see in the simulator.

        textLabel.zPosition = 2
        textLabel.fontColor = .white
        textLabel.position = pos
        textLabel.fontSize = 20
        self.addChild(textLabel)

Also, depending on how much stuff is added to the screen and the zPosition you might have to either bump the node up infront of another node, or remove and insert the node again to place it atop the existing stuff.

Dave Levy
  • 1,036
  • 13
  • 20