3

So I have placed a 3D Text Node in my SCN scene and I would like to change the value of the Text property later in my application

SceneKit Inspector

enter image description here

Above is how I change the value of the text from the inspector but is there a way to do it programmatically? thank you

Joseph Hajjar
  • 138
  • 2
  • 12

3 Answers3

5

When you instantiate a "3D Text" object from the Object Library in Xcode, what you get is a SCNNode that has a SCNText as its geometry.

if let textGeometry = textNode.geometry as? SCNText {
    textGeometry.string = "something"
}
mnuages
  • 13,049
  • 2
  • 23
  • 40
0

So if you have linked your text node with your game scene, programmatically you can do:

textNode.geometry.string = "your string"

It should work!

0

This is what worked for me. Assume you've added a 3D Text Node in interface builder and it's called "CountDownText" in the node hierarchy.

In the relevant view controller, I have two properties:

var countDownText: SCNNode!
var theCountDownText: SCNText!

Later, bind the node from the interface builder to the code (in a set up node function):

countDownText = scnScene.rootNode.childNode(withName: "CountDownText", recursively: true)
theCountDownText = countDownText.geometry as! SCNText

Any time you want to change the display text of that node, you can just do as follows:

theCountDownText.string = "text"
Diskprotek
  • 601
  • 2
  • 7
  • 13