0

I'm using the SKScene editor of XCode to create scenes for a game using SpriteKit. I can successfully add sprites, lights, nodes, labels... and use it in the code but I don't find how to add a SKLabel using the SKScene editor of Xcode.

Is it possible to add SKLabel with the SKScene editor like for the other objects (Sprite, Node, Light, Label...) or is it only possible programmatically ?

Jonah Begood
  • 317
  • 2
  • 14
  • You say you've successfully added labels to the scene in the editor. Labels you create in the editor are instances of `SKLabelNode`. What problem are you having, exactly? – rickster Jul 20 '15 at 19:19
  • Then I don't know how to access to these labels as ‘SKLabelNode‘ from my code. For a sprite I use `childNodeWithName` with the name defined in the editor to find it. If I do this with a label created in the editor, I have an error (`MyLabel = self.childNodeWithName("LabelName") as SKLabelNode`) – Jonah Begood Jul 21 '15 at 07:23

1 Answers1

0

In order to access the label you must use an if statement:

let spriteKit = SKScene(fileNamed: "spriteKitFile")
if let label = spriteKit?.childNode(withName: "name of the file") as? SKLabelNode {
    label.text = "Any string"
}
scopchanov
  • 7,966
  • 10
  • 40
  • 68
fannolo
  • 357
  • 3
  • 10