SKLabelNode没有显示出来

时间:2016-07-01 16:19:20

标签: ios swift sprite-kit sklabelnode

我试图让SKLabelNode显示在我的屏幕上,但它没有显示。这是我的代码......

 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) }

我做错了什么?

3 个答案:

答案 0 :(得分:1)

你只需要给你的标签一个位置:

textLabel.position = CGPoint(x:500, y:200)

答案 1 :(得分:1)

代码应写为

textLabel.text = "Hi there"

而不是

textLabel.text? = "Hi there"

答案 2 :(得分:0)

我有同样的问题。

我的解决方案是这样的...

不是textLabel.color = UIColor.white

textLabel.fontColor = UIColor.white

相关问题