libGDX:将TextureRegion转换为纹理

时间:2017-07-11 20:59:18

标签: libgdx textures texturepacker

如何将龙用作纹理?

atlas = new TextureAtlas("myPack.atlas"); 
dragon = dragon.findRegion("dragon"); // returns TextureRegion

1 个答案:

答案 0 :(得分:0)

Texture创建TextureRegion毫无意义。

您的TextureRegion具有纹理的矩形点,因此您可以将特定纹理像素写入像素图,然后从Texture创建Pixmap

TextureAtlas.TextureAtlasData.Region dragon = atlas.getRegion("dragon");
Pixmap pixmap = new Pixmap(dragon.width, dragon.height, Pixmap.Format.RGBA8888);
FileHandle pngFile = dragon.page.textureFile;

Pixmap completePix = new Pixmap(pngFile);
pixmap.drawPixmap(completePix, 0, 0, dragon.left, dragon.top, dragon.width, dragon.height);

Texture dragonTex=new Texture(pixmap);