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

查看:30
本文介绍了如何缓存或预加载 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天全站免登陆