Java LibGDX:使用相同的TextureAtlas两次或使用两个不同的TextureAtlas

Java LibGDX:使用相同的TextureAtlas两次或使用两个不同的TextureAtlas,java,libgdx,Java,Libgdx,我正在将我的原生Android游戏迁移到libGDX。这就是我使用翻转图形的原因。显然,NinePatches不能翻转。(它们是不可见的或不可见的。) 更有效的方法是: 使用一个包含所有图形文件的大TextureAtlas,并加载两次(翻转和未翻转)或 对翻转的图形文件使用一个大的TextureAtlas,对NinePatch图形使用第二个小的 A类: public static TextureAtlas atlas, atlas2; public static void load() {

我正在将我的原生Android游戏迁移到libGDX。这就是我使用翻转图形的原因。显然,
NinePatch
es不能翻转。(它们是不可见的或不可见的。)

更有效的方法是:

  • 使用一个包含所有图形文件的大
    TextureAtlas
    ,并加载两次(翻转和未翻转)或
  • 对翻转的图形文件使用一个大的
    TextureAtlas
    ,对NinePatch图形使用第二个小的
A类:

public static TextureAtlas atlas, atlas2;

public static void load() {
    // big atlas (1024 x 1024)
    atlas = new TextureAtlas(Gdx.files.internal("game.atlas"), true); 
    // find many AtlasRegions here

    // Same TextureAtlas. Loaded into memory twice?
    atlas2 = new TextureAtlas(Gdx.files.internal("game.atlas"), false);
    button = ninepatch.createPatch("button");
    dialog = ninepatch.createPatch("dialog");
}
B类:

public static TextureAtlas atlas, ninepatch;

public static void load() {
    // big atlas (1024 x 1024)
    atlas = new TextureAtlas(Gdx.files.internal("game.atlas"), true); 
    // find many AtlasRegions here

    // small atlas (128 x 64)
    ninepatch = new TextureAtlas(Gdx.files.internal("ninepatch.atlas"), false); 
    button = ninepatch.createPatch("button");
    dialog = ninepatch.createPatch("dialog");
}

现在我没有时间来测试,我阐述了这个想法,但我认为它可以工作,是基于纹理,而不是简单的纹理图谱

short metadata = 2;

Texture yourTextureMetadata = new Texture(Gdx.files.internal(metaDataTexture));

int width  = yourTextureMetadata.getWidth()   - metadata;
int height = yourTextureMetadata.getHeight()  - metadata;

TextureRegion yourTextureClean = new TextureRegion(yourTextureMetadata, 
                                             1, 1, width, height);
我假设元数据的大小为2,现在我不记得了,对不起

这个想法将采取,最大的纹理,元数据,然后削减他们有干净的另一面,这样你可以转身,我希望工作

对于TextureTas,类似的做法是查找区域并剪切元数据,然后保存它们而不保存元数据


另一方面,请注意,您有静态纹理,我认为当android将上下文、您的应用程序更改为另一个应用程序,然后返回到您的应用程序时,您可以将错误可视化,您的图像可以以黑色显示,最终会出现大量纹理交换,这可能会严重降低性能。有什么原因不能在生成纹理图集之前翻转资产吗?谢谢你的评论!我认为翻转所有png文件是一个很好的选择(如果我可以用脚本自动化的话);转换$file-flip mdpi_fliped/$file;完成谢谢您的回答。我没有投反对票。但我不明白你的意思。是关于剪切.9.png文件的1像素边框吗?我想这是自动发生的。@MaxGyver啊,现在我明白了,你的问题是,当然,我的英语很差,虽然quiras有一个有元数据的纹理,一个没有元数据,但很抱歉回答不好。关于静态纹理:是的,我知道我必须处理它们。也许创建资产类的实例更容易。