在游戏中将 SKTextureAtlas 拆分为多个级别的最佳方法是什么?

What is the best way to split an SKTextureAtlas for multiple levels in a game?

目前我有一个 SKTextureAtlas 太大无法快速加载。它包含我游戏中所有敌人的纹理。我想拆分图集,以便游戏仅加载特定级别所需的纹理。但是,一些敌人出现在多个级别。我应该如何拆分图集?我不想为每个级别创建一个图集,因为我必须为重复的敌人复制图像文件,并且当有很多级别时它会变得很烦人。有没有更优雅的方法?

一个很好的场景是整个关卡屏幕上所有可见的精灵都进入同一个纹理图集中。在这种情况下,Texture Atlas 被加载到 GPU 中并保留在那里。 在每一帧中,CPU 只需要通知 GPU 关于每个精灵的 coordinates/positions/transformations,节省了大量的数据传输。

我知道这可能会迫使您复制一些 sprite,因为其中一些可以在多个级别使用。只有您(作为您的游戏开发者)才能接受。

来自Apple docs

When you create a texture atlas, you want to strike a balance between collecting too many textures or too few. If you use too few images, SpriteKit may still need many drawing passes to render a frame. If you include too many images, then large amounts of texture data may need to be loaded into memory at once. Because Xcode builds the atlases for you, you can switch between different atlas configurations with relative ease. So experiment with different configurations of your texture atlases and choose the combination that gives you the best performance.