libgdx纹理打包器查找、存储和使用区域示例

libgdx纹理打包器查找、存储和使用区域示例,libgdx,pack,texturepacker,Libgdx,Pack,Texturepacker,我正在使用纹理打包器 为了我的libgdx游戏。我也创建了包文件。现在我有一个气球和一个 balloon\u burst\u pack.pack文件 唯一的问题是,从在线文档中,我不知道如何准确地从pack文件中检索所有15个png图像 我的图像名称像balloon\u color\u 0001.png、balloon\u color\u 0002.png,我将它们打包在一个balloon\u packed.png中 我尝试过的小代码是: atlas = new TextureAtlas(Gd

我正在使用纹理打包器

为了我的libgdx游戏。我也创建了包文件。现在我有一个气球和一个
balloon\u burst\u pack.pack文件

唯一的问题是,从在线文档中,我不知道如何准确地从pack文件中检索所有15个png图像

我的图像名称像balloon\u color\u 0001.png、balloon\u color\u 0002.png,我将它们打包在一个balloon\u packed.png中

我尝试过的小代码是:

 atlas = new TextureAtlas(Gdx.files.internal("Animations/balloon_color_pack/balloon_burst_pack.pack"));

   for (int i = 0; i< 15;i++ ) {

        region[i] = atlas.findRegion("balloon_colour"+"000"+i);
        System.out.println("region detected is"+region[i].getRegionX());
   }
atlas=new TextureAtlas(Gdx.files.internal(“动画/balloon\u color\u pack/balloon\u burst\u pack.pack”);
对于(int i=0;i<15;i++){
区域[i]=atlas.findRegion(“气球颜色”+“000”+i);
System.out.println(“检测到的区域是”+区域[i].getRegionX());
}
任何人谁使用相同的纹理包装请给我参考使用包装文件。 如果可能的话,请一步一步地给我解释


谢谢。

您的png名称存在的问题是,纹理打包器会将所有名称修剪在第一个“\u1”之后 因此,您必须将png的名称更改为BallooColor_0001.png、BallooColor_0002.png等,而不是Balloo_color_0001.png等,然后使用kumar saurabh的代码加载所有文件


或者在当前设置中,当您使用
纹理打包工具和打包图像时,您可以使用名称作为气球而不是气球颜色

,其提供的
气球爆破包装.png
文件及其相关打包文件
气球爆破包装.pack
(例如)其中包含一个
balloon\u burst\u pack.png
文件中所有图像的
x
y
坐标(根据它们的名称)。
例如,您可以在
balloon\u burst\u pack.pack
中找到
x
y
气球颜色0001.png的坐标和大小。一旦你找到了它的坐标和大小,你就可以通过
TextureRegion
类得到它

Texture balloonBrust = new Texture(Gdx.files.internal("path of your balloon_burst_pack.png file"));
TextureRegion baloon1Region = new TextureRegion(balloonBrust ,x coordinate ,y coordinate, width, height);
现在,您可以使用
SpriteBatch
class绘制它

Texture balloonBrust = new Texture(Gdx.files.internal("path of your balloon_burst_pack.png file"));
TextureRegion baloon1Region = new TextureRegion(balloonBrust ,x coordinate ,y coordinate, width, height);