Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pack images into one .png file using TexturePacker2?

Tags:

libgdx

Right now I pack images like this:

TexturePacker2.Settings settings = new TexturePacker2.Settings();
settings.flattenPaths = true;
settings.combineSubdirectories = true;
TexturePacker2.process(directory, "pack", atlasName);

But if there are many subdirectories in directory, then for each subdirectory TexturePacker2 creates a separate .png file with suffixes 1, 2, 3 and so on. How can I tell it to pack all images in all subdirectories into one .png file?

like image 689
gvlasov Avatar asked Dec 03 '25 11:12

gvlasov


2 Answers

See this link for more information on the TexturePacker2. Putting every subdirectory in an own packfile is the default behaviour, because most of the time you don't want everything in one file, because it would get too big. This way you can organize your textures in groups. One very simple way to avoid this behaviour would be to put everything into one directory and then use the gdx-texturepacker.jar UI to pack it, telling it to use a max width/height of 4096 or maybe even more. The UI does not offer you combineSubdirectories and flattenPaths though.

Thus going the "code way" was the right choice. This offers you all possibilities of the TexturePacker2. It also lets you define the maximum size of one page by setting maxWidth and maxHeight in the TexturePacker2.Settings. If this is high enough, the packer will not need to create several pages.

like image 109
noone Avatar answered Dec 05 '25 20:12

noone


Instead of:

TexturePacker2.process(directory, "pack", atlasName);

you should use:

TexturePacker2.process(settings, directory, "pack", atlasName);
like image 30
Milan Babuškov Avatar answered Dec 05 '25 21:12

Milan Babuškov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!