libgdx texture packer finding ,storing and using regions example

2.3k views Asked by At

I am using Texture packer libgdx texture packer

for my libgdx game . I have created pack file also . now I have one balloon_burst_pack.png and one
balloon_burst_pack.pack file.

only thing is from online documentation I cant figure out how exactly should i retrieve all 15 png images from pack file.

my image names are like balloon_color_0001.png, balloon_color_0002.png which I have packed in one balloon_packed.png

small code i have tried is :

 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());
   }

anyone who have used same texture packer please give me reference to use packed file . please explain me step by step if possible..

Thanks.

2

There are 2 answers

0
Vikalp Jain On

The problem with your png names is that texture packer trims all names after first '_' so you must change the names of your png to something like ballooncolor_0001.png, ballooncolor_0002.png etc insted of balloon_color_0001.png etc then use kumar saurabh's code to load all the file

or eith current setup you can use name as balloon instead of ballon_color

0
Vishal Singh On

When you use Texture Packer tool and pack images its provides balloon_burst_pack.png file and its related packer file balloon_burst_pack.pack(for example) which contain x and y coordinate of all images in one balloon_burst_pack.png file according to their names.
For example you can find x and y coordinates and size of balloon_color_0001.png in balloon_burst_pack.pack. Once you find its co-ordinate and size you can get it by TextureRegion 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);

now you can draw it using SpriteBatch class.