Reputation: 115
I have a SKS file with a Color Sprite defined as a box, and a Label in it. The Label parent is the box, so when I use:
let box = childNodeWithName("mybox") as SKSpriteNode
let labeltxt = childNodeWithName("mylabel") as SKLabelNode
The program returns an error:
fatal error: unexpectedly found nil while unwrapping an Optional value
Someone knows how to change the value of the text of "mylabel"?
Upvotes: 2
Views: 279
Reputation: 91
If the label is a child of box you create a constant declaring the label node
let labeltxt = box.childNodeWithName("mylabel") as SKLabelNode
Upvotes: 1