Launching SKLabelNode Application

I'm currently coding a small application with SpriteKit that works fine, but the only problem is SKLabelNode, which I initialize with the following normal code snippet:

​self.scoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Futura"]; self.scoreLabel.fontSize = 190.0f; self.scoreLabel.color = [SKColor whiteColor]; self.scoreLabel.alpha = .2; self.scoreLabel.text = @"00"; self.scoreLabel.position = CGPointMake(screenWidth/2,self.scoreLabel.frame.size.height/2); [self addChild:self.scoreLabel]; 

There are many other things to initialize, but they do not affect anything. If I comment on the above code, the application loads at normal times. With SKLabelNode, it delays loading for a few seconds ...

Hope someone can help me.

+6
source share
3 answers

You need to preload the font so that when you first call your SKScene sprite kit, the font in memory is already ready. The best way to do this is to either use the application delegate or the singleton as soon as you can in the game life cycle.

 self.scoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Futura"]; self.scoreLabel.text = @"preload"; 

You don’t need to make the shortcut global, just make sure you keep a strong link so that the compiler knows that you want to keep the font in memory. Also make sure that you set the text property (the font only loads when it is installed).

EDIT:

This is what I use:

 - (void)setupFonts { SKLabelNode *preloadFontLabel = [SKLabelNode labelNodeWithFontNamed:@"HelveticaNeue-UltraLight"]; [preloadFontLabel setText:@"Preload"]; } 

This is called from singleton game assets right when the game starts, I also have a callback that stops the β€œPLAY” button that appears before loading the assets, so the user cannot jump from the gun until everything is up and loaded. My game resources take only 1.03 seconds. Therefore, this is not a problem, but if necessary, you can hide a large load behind the splash / launch screen.

If you still see the problem, I would check that you do not have other fonts in your SKScene that you did not preload. There may also be a problem loading a custom font, try changing the font to "HelveticaNeue-UltraLight" and see if you get the same problem.

+2
source

In fact, you do not need to preload the font for SKLabelNode. The delay is caused by the fact that you are using the wrong font name. There is no "Futura" font on iOS - what you probably mean is "Futura-Medium." Replace "Futura" with "Futura-Medium" and you will see that the load time drops sharply.

(You can still preload your fonts, but it's not necessary, lazy loading is pretty fast provided that you use the correct font name.)

+9
source

Be careful, you are not downloading the entire font family. If I download "Chalkboard SE", it takes 4-6 seconds and seems to work.

But if I load ChalkboardSE-Regular, it is almost instantly ~ 100 ms or less.

If you want to know more, I have different links and timings on my humble blog. https://gilesey.wordpress.com/2015/01/14/ios-spritekit-font-loading-times-of-sklabelnodes/

+5
source

All Articles