Example usage for com.badlogic.gdx.tiledmappacker TiledMapPacker TiledMapPacker

List of usage examples for com.badlogic.gdx.tiledmappacker TiledMapPacker TiledMapPacker

Introduction

In this page you can find the example usage for com.badlogic.gdx.tiledmappacker TiledMapPacker TiledMapPacker.

Prototype

public TiledMapPacker() 

Source Link

Document

Constructs a new preprocessor by using the default packing settings

Usage

From source file:com.ridiculousRPG.map.OnChangeMapPacker.java

License:Apache License

public void packOnChange() {
    try {//from  w  w  w.j  a va 2  s .c om
        boolean packMaps = false;
        if (!mapOutDir.exists()) {
            mapOutDir.mkdirs();
            packMaps = true;
        } else {
            try {
                BufferedReader checkUpdate = new BufferedReader(
                        new FileReader(mapOutDir + File.separator + "check.txt"));
                File[] tmxFiles = mapInDir.listFiles(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.toLowerCase().endsWith(".tmx");
                    }
                });
                Arrays.sort(tmxFiles);
                for (File tmx : tmxFiles) {
                    String line = checkUpdate.readLine();
                    if (line == null || !line.startsWith(tmx.getName())
                            || !line.endsWith(String.valueOf(tmx.lastModified()))) {
                        packMaps = true;
                        break;
                    }
                    TiledMap tmxMap = TiledLoader.createMap(Gdx.files.absolute(tmx.getAbsolutePath()));
                    for (TileSet tileSet : tmxMap.tileSets) {
                        File img = new File(mapInDir, tileSet.imageName);
                        line = checkUpdate.readLine();
                        if (line == null || !line.startsWith(img.getName())
                                || !line.endsWith(String.valueOf(img.lastModified()))) {
                            packMaps = true;
                            break;
                        }
                    }
                }
                checkUpdate.close();
            } catch (Exception packIt) {
                packMaps = true;
            }
        }
        if (packMaps) {
            Gdx.files.absolute(mapOutDir.getAbsolutePath()).deleteDirectory();
            TexturePacker.Settings settings = new TexturePacker.Settings();
            settings.defaultFormat = Format.RGBA8888;
            settings.stripWhitespace = true;
            settings.incremental = true;
            settings.alias = true;
            new TiledMapPacker().processMap(mapInDir, mapOutDir, settings);

            // write info-file
            PrintWriter checkUpdate = new PrintWriter(mapOutDir + File.separator + "check.txt");
            File[] tmxFiles = mapInDir.listFiles(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".tmx");
                }
            });
            Arrays.sort(tmxFiles);
            for (File tmx : tmxFiles) {
                checkUpdate.println(tmx.getName() + " / " + tmx.lastModified());
                TiledMap tmxMap = TiledLoader.createMap(Gdx.files.absolute(tmx.getAbsolutePath()));
                for (TileSet tileSet : tmxMap.tileSets) {
                    File img = new File(mapInDir, tileSet.imageName);
                    checkUpdate.println(img.getName() + " / " + img.lastModified());
                }
            }
            checkUpdate.close();
        }
    } catch (Exception e) {
        GameBase.$error("OnChangeMapPacker", "Could not pack the map (maybe no write permission)", e);
    }
}

From source file:net.k3rnel.unsealed.utils.TiledMapAtlasGenerator.java

License:Open Source License

public static void main(String[] args) {
    // create the packing's settings
    Settings settings = new Settings();
    settings.maxHeight = 1024;//from   w ww .j  av a2s .  co m
    settings.maxWidth = 1024;

    //Creates temp file variables
    File inputDir = new File(INPUT_DIR);
    File outputDir = new File(OUTPUT_DIR);
    try {
        //We delete the old files, because otherwise, we'd get cluttered with pngs
        deleteRecursive(outputDir);
        //We remake the folders
        outputDir.mkdirs();
        //We pack the tiles in a warm little blanket.
        new TiledMapPacker().processMap(inputDir, outputDir, settings);
    } catch (IOException e) {
        e.printStackTrace();
    }
}