如何缓存或预加载SKLabelNode字体? [英] How to cache or preload SKLabelNode font?

查看:495
本文介绍了如何缓存或预加载SKLabelNode字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作一个Sprite Kit应用程序,在我的场景中,我添加了一个SKLabelNode。我注意到一个相当大的滞后尖峰,当我加载SKScene。在剖析应用程序后,我发现它来自创建一个纸莎草字体的SKLabelNode(虽然字体没有关系)。当我删除标签时,场景几乎立即启动,但是使用标签需要额外的1-3秒。

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 creating an SKLabelNode with a papyrus font(though the font doesn't matter). When I remove the label the scene starts up almost instantaneously, but with the label it takes an extra 1-3 seconds.

我确定它是从加载字体,当我回到主菜单,玩游戏,它再次启动立即。

I am pretty sure it's from loading the font as when I go back to the main menu and play the game again it starts up instantly again.

现在有一种方法可以预先加载字体,所以当播放器选择级别没有大的暂停?

Now is there a way to preload the font earlier so when the player selects the level there isn't a large pause?

推荐答案

我们有这个问题,原来,我们只是不使用正确的字体名称。在我们的例子中,我们在实例化我们的SKLabelNode时使用Menlo而不是Menlo-Regular,并且会产生几秒钟的惩罚。一旦我们使用正确的字体名称,延迟不再发生。

We had this issue, and it turned out that we were simply not using the "correct" font name. In our case, we were using "Menlo" instead of "Menlo-Regular" when instantiating our SKLabelNode, and it was incurring the several-second penalty. Once we used the correct font name, the delay no longer happened.

(奇怪的是,SKLabelNode仍然找到Menlo并使用它,所以不是很明显,错误的字体名称。推测,延迟是由系统必须找出合适的替代使用,这是一个很好的工作,找到我们打算使用的字体,但它需要一段时间来做,因此延迟。)

(Curiously, the SKLabelNode still found Menlo and used it, so it was not immediately obvious that we had the wrong font name. Presumably, the delay is caused by the system having to figure out the appropriate substitute to use. It does a good job, finding the font we intended to use, but it takes a while to do it, hence the delay.)

这篇关于如何缓存或预加载SKLabelNode字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆