Reputation: 148
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
Above is how I change the value of the text from the inspector but is there a way to do it programmatically? thank you
Upvotes: 3
Views: 3865
Reputation: 601
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"
Upvotes: 0
Reputation: 13462
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"
}
Upvotes: 5
Reputation: 1048
So if you have linked your text node with your game scene, programmatically you can do:
textNode.geometry.string = "your string"
It should work!
Upvotes: 0