1

I want to load the font once and use it for the other sklabel nodes

let originalLabel: SKLabelNode = SKLabelNode(fontNamed: "fontName");

and later

var labelNode = originalLabel;
var labelNodeSecond = originalLabel;

but that gives the following error

Attemped to add a SKNode which already has a parent: SKLabelNode

grape1
  • 759
  • 2
  • 8
  • 19

1 Answers1

2

You can set the font once by initializing an UIFont:

let yourFont = UIFont(name: "yourfontName", size: 17)

var firstLabel = SKLabelNode(fontNamed: yourFont?.fontName) 
var secondLabel = SKLabelNode(fontNamed: yourFont?.fontName)

That way, you only set the font once and the SKLabelNodes don't have to load it by themself.

Christian
  • 22,585
  • 9
  • 80
  • 106
  • Thanks Christian this little make the game 40x faster, because I am creating 8 sklabelnodes and it was very slow even the name of the font is right! Once again thanks for the help – grape1 Apr 28 '15 at 15:11