How to cache or preload SKLabelNode font?

后端 未结 2 1643
一向
一向 2020-11-30 14:47

I\'m making a Sprite Kit app and in my scene I added an SKLabelNode. I noticed a pretty large lag-spike when I load the SKScene. After profiling the app I found it came from

2条回答
  •  一个人的身影
    2020-11-30 15:00

    I had the same issue. Add following code to your very first scene, with your font name:

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

    If you don't provide text it won't load font. Note that you don't need to add label as child to your scene.

提交回复
热议问题