为了用精灵渲染清晰的图形,我决定为每个分辨率大小提供一个专用的精灵文件夹。我有55 个这样的文件夹,每个文件夹包含57 个.png
文件(这意味着总数是 57*55 = 3135 个文件)。我将所有 55 个文件夹放入一个文件夹中,然后Texture Packer
在该文件夹上运行。在输出文件夹中,我得到 1 个pack.atlas
文件和 212 个 packX.png
文件(X 从 1 运行到 212)
在我的代码中,我在我的Assets
类中创建了这些字段
private static TextureAtlas atlas;
private static Sprite logo;
// ... total of 57 Sprite fields....
Assets
而在游戏开始时调用的类的initialize方法中:
atlas = new TextureAtlas(Gdx.files.internal("pack.atlas"));
logo = atlas.createSprite(getWidthPath() + "logo"); //getWidthPath() returns the appropriate folder path based on the resolution size. As stated above, there are 55 such folder
//...atlas.createSprite 57 times for 57 fields....
我已经为较少数量的文件夹(3 个文件夹)完成了此操作,并且游戏运行良好。但是,当我决定支持所有 55 分辨率文件夹时,游戏无法在 Android 上加载,可以在桌面上加载,但一开始真的很慢。
那么pack.atlas
文件引用的大量 Sprite 是否会导致挂起?
我想如果我只TexturePacker
在每个分辨率文件夹上运行,我将得到 55pack.atlas
个文件(而不是 1 个),每个pack.atlas
文件现在将引用 57 个精灵(而不是 3135 个文件),游戏应该可以正常运行,但是太费力了