ChristLarsen
ChristLarsen

Reputation: 115

Cannot use childNodeWithName with a Sprite with a parent defined in SKS

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

Answers (1)

dominikweifieg
dominikweifieg

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

Related Questions