简体   繁体   English

libGDX从图像文件夹创建图集

[英]libGDX create an atlas out of a folder of images

I am following a tutorial at Game from Scratch 我正在从零开始关注Game

I am confused at the following: 我对以下内容感到困惑:

java -cp gdx.jar;extensions/gdx-tools/gdx-tools.jar com.badlogic.gdx.tools.imagepacker.TexturePacker2 c:\\tmp c:\\tmp spritesheet tmp

I have a required folder with images how do I convert it into an atlas? 我有一个包含图像的必填文件夹,如何将其转换为地图集?

This question might sound feeble, I am just a beginner. 这个问题听起来微不足道,我只是一个初学者。 Any help would be great :) 任何帮助将是巨大的:)

Place all images you want to be in final atlas in one folder and its subfolders. 将所有要保存在最终地图集中的图像放在一个文件夹及其子文件夹中。 Create pack.json file with configuration in the folder and each subfolder (optional step). 在文件夹和每个子文件夹中创建带有配置的pack.json文件(可选步骤)。 Run following code (save it into MyPacker.java file) : 运行以下代码(将其保存到MyPacker.java文件中):

import com.badlogic.gdx.tools.texturepacker.TexturePacker;
public class MyPacker {
   public static void main (String[] args) throws Exception {
       TexturePacker.process(inputDir, outputDir, packFileName);
 }
}

It may take a some time (seconds or even minutes) to finish. 可能需要一些时间(几秒钟甚至几分钟)才能完成。 The process may result in more than one texture atlases. 该过程可能导致不止一个纹理图集。 Please note that not only picture altas will be created but also a *.atlas file describing content of the atlas. 请注意,不仅将创建图片altas,而且还将创建描述地图集内容的*.atlas文件。

Created atlas can be used as source of textures following way: extureAtlas atlas; 创建的图集可以按以下方式用作纹理源:extureAtlas图集;

TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("packedimages/pack.atlas"));
AtlasRegion region = atlas.findRegion("imagename");
Sprite sprite = atlas.createSprite("otherimagename");

Please read the current documentation to see other options and details about pack.json configuration files. 请阅读当前文档以查看关于pack.json配置文件的其他选项和详细信息。

Try the GUI version of texturepacker, its quite simple to use. 尝试使用GUI版本的texturepacker,它使用起来非常简单。

https://code.google.com/p/libgdx-texturepacker-gui/ https://code.google.com/p/libgdx-texturepacker-gui/

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM