SKLabelNode.name target for setText

131 views Asked by At

Question

How to target an SKLabelNode by name? to change it's text?

Example;

SKNode *node = [self childNodeWithName:string];
[node setText:value];

How does one achieve this? I cannot do it by targeting it's instance variable as I have multiple under the same name, however, all have different names. I just cannot figure out how to target it with an sknode.

And to try and do it with an SKLabelNode *node =... Then it is incompatible.

Any help is much appreciated, thank you.

2

There are 2 answers

0
Daniel On BEST ANSWER

Going back through my questions and sorting them out.

SKNode *node = [self childNodeWithName:string];
SKLabelNode *label = (SKLabelNode *)node;

label.text = @"dwadw";
0
Shades On

The conversion to Swift is pretty straightforward, but here it is anyway:

let node = self.childNodeWithName("nodeName")
let labelToUpdate = node as! SKLabelNode

labelToUpdate.text = "Your text here"