Centre a SKLabelNode on a SKSpriteNode

后端 未结 3 1155
半阙折子戏
半阙折子戏 2021-02-19 20:18

I have an SKLabelNode that is the child of a SKSpriteNode because I\'m trying to create a Button class to create buttons in an easier way. I\'ve tried a couple of things using t

3条回答
  •  情书的邮戳
    2021-02-19 20:47

    Swift 4.2 XCode 10.1

    Copy this function into your SceneKit Class

    func createLabel(text: String) {
            let label = SKLabelNode(fontNamed: "Wicked Mouse")
    
            label.text = text
            label.fontColor = .white
            label.position = CGPoint(x: self.size.width / 2, y: self.size.height / 2)
            label.verticalAlignmentMode = .center
            label.horizontalAlignmentMode = .center
            label.fontSize = 30.0
            label.zPosition = 1
            self.addChild(label)
        }
    

提交回复
热议问题