且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SpriteKit中没有工作转换

更新时间:2023-11-17 16:00:28

如果新场景特别重要资源,即需要大量的纹理加载,这将延迟任何帧渲染。如果纹理加载花费的时间比转换时间长,则会丢失所有内容,因为在转换完成后,将显示第一帧。
我也碰到了这个,虽然我能够更好地确定根本原因,因为我有2秒的转换,其中只显示了最后0.5秒。

If the new scene is particular resource heavy, i.e., requires a lot of texture loading, that will delay any frame rendering. If the texture loading takes longer than your transition time, you will miss all of it because the first frame that will be displayed has been rendered after your transition is finished. I ran into this as well, although I was better able to determine the root cause because I had a transition of 2 seconds of which only the last 0.5 seconds were shown.

如何解决这个问题?预加载纹理。请参阅 Apple Docs

How to fix this? Preload your textures. See Apple Docs.

+ (void)preloadTextures:(NSArray *)textures withCompletionHandler:(void (^)(void))completionHandler

我应该强调 SKSprite SKTexture 和你的image.png。
SKSprite 根据其纹理属性(或背景$)绘制自己c $ c> color)和 size 。您可以将一个SKTexture用于许多精灵。反过来,图像文件(image.png)可以提供多个SKTexture对象。

I should emphasize the differences between SKSprite, SKTexture and your "image.png". SKSprite draws itself based on its texture property (or background color), and size. You can use one SKTexture for many sprites. In turn, an image file ("image.png") can supply multiple SKTexture objects.

重要提示:您希望使用传递给SKTexture对象的数组中的纹理上面的方法实际上受益于纹理加载。这个需要某种形式的纹理管理。

Important: you want to use textures from the array of SKTexture objects passed to the method above to actually benefit from the texture loading. This will require some form of texture management.

如果您的问题确实与纹理有关,请告诉我您是否需要我扩展纹理管理。可以在此处找到相关帖子(可能有点干): SO sktexture-preloading

If your problem is indeed texture related, let me know if you need me to expand on the texture management. A related post (which may be a bit dry) can be found here: SO sktexture-preloading.