调用SKLabelNode时延迟? [英] Delay when calling SKLabelNode?
问题描述
从一个SKScene
转换到另一个SKScene
时,我有一个稍微延迟(滞后)的问题.通过注释掉各种代码,我将其范围缩小到了SKLabelNode
,我的猜测是这是它在调用时加载/缓存字体,这在陈述新的SKScene
时导致较小的延迟/停顿.
I am having a problem with a slight delay (lag) when transitioning from one SKScene
to another. By commenting out various bit of code I have narrowed this down to SKLabelNode
, my guess is thats its loading / caching the font when called which is resulting in a small delay/stutter when stating up the new SKScene
.
其他任何人都注意到了这一点,当您仅使用单个SKScene
(如默认模板)时,这种情况就不太明显了,因为减速通常会在通常的启动延迟中丢失.有谁知道解决这个问题的方法,有没有办法预加载字体?我想我可以在启动时将字体加载到UIViewController
上,看看是否可以通过SKScene
来访问它,任何人有什么想法吗?
Has anyone else noticed this, its less obvious when your just using a single SKScene
(like the default template) as the slowdown just gets lost in the usual startup delay. Does anyone know a way round this, is there a way to pre-load the font? I guess I could load the font on the UIViewController
at startup and see if I could access it from with the SKScene
, anyone any ideas?
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
[self setScore:0];
[self setBackgroundColor:[SKColor blackColor]];
SKLabelNode *labelNode = [SKLabelNode labelNodeWithFontNamed:@"System"];
[labelNode setText:@"00000"];
[labelNode setFontSize:20.0];
[labelNode setPosition:CGPointMake(CGRectGetMidX(self.frame),500)];
[labelNode setName:@"SCORE"];
[labelNode setAlpha:1.0];
[self addChild:labelNode];
[self setScoreLabel:labelNode];
...
推荐答案
延迟是基于字体的加载.最好预先加载要使用的字体,声音和任何其他资源,以免第一次实际使用时出现延迟.
The delay is based on the loading of your font. Best to preload fonts, sounds, and any other assets you intend to use, so that you don't have a delay when it's actually used the first time.
您可以使用:
SKLabelNode *preload = [SKLabelNode labelNodeWithFontNamed:@"System"];
[preload setText:@"anything"];
如评论中所述,仅当使用无法通过iOS使用的字体时才需要预加载.
As noted in the comments, preloading is only needed when using a font that is not available via iOS.
这篇关于调用SKLabelNode时延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!