How to cache or preload SKLabelNode font?

I am building a Sprite Kit application, and in my scene I added SKLabelNode. When I load SKScene, I noticed a pretty big lag splash. After profiling the application, I found that this came from creating SKLabelNode with a papyrus font (although the font does not matter). When I delete a shortcut, the scene starts almost instantly, but with a tag takes an additional 1-3 seconds.

I am sure that from downloading the font, when I return to the main menu and play the game again, it starts up again.

Now there is a way to preload the font earlier, so when the player selects a level, there is no big pause?

+4
source share
2 answers

We had this problem, and it turned out that we just did not use the "correct" font name. In our case, we used “Menlo” instead of “Menlo-Regular” when creating our SKLabelNode, and it executed a penalty of a few seconds. When we used the correct font name, there was no longer any delay.

(Curiously, SKLabelNode still found Menlo and used it, so it didn't immediately become obvious that we had the wrong font name. Presumably, the delay was caused by the system having to find a suitable replacement to use. Good job, finding the font we intended to be used, but this takes some time, hence the delay.)

+13
source

. :

SKLabelNode *preload = [SKLabelNode labelNodeWithFontNamed:@"Avenir"];
preload.text = @"text";

, . , .

+3

All Articles