Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programatically Generated Maps don't finish() #329

Closed
ghost opened this issue Apr 3, 2020 · 1 comment
Closed

Programatically Generated Maps don't finish() #329

ghost opened this issue Apr 3, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 3, 2020

Creating a new map via the following code does not finish() according to my debugging
at drawTile(), all the tiles are null.

        TmxMap map = new TmxMap(MapOrientations.ORTHOGONAL);
        map.setRenderOrder(RenderOrder.RIGHT_DOWN);
        map.setTileWidth(64);
        map.setTileHeight(64);
        map.setWidth(10);
        map.setHeight(10);
        map.setTiledVersion("1.1.5");
        map.setName(name);

        Tileset tileset = Resources.tilesets().get("tilesheet.tsx");
        map.getTilesets().add(tileset);

        ArrayList<Tile> tiles = new ArrayList<>();
        for (int y= 0; x < 10; x++) {
            for (int x= 0; y < 10; y++) {
                int tile = 1;
                Tile t = new Tile(tile);
                t.setTileCoordinate(new Point(x,y));
                tiles.add(t);
            }
        }

        TileData data;
        try {
            data = new TileData(tiles, width, height, TileData.Encoding.CSV, TileData.Compression.NONE);
            data.setValue(TileData.encode(data));
        } catch (IOException e) {
            data = null;
            e.printStackTrace();
        }

        try {
            System.out.println(data.getTiles());
        } catch (InvalidTileLayerException e) {
            e.printStackTrace();
        }

        TileLayer ground = new TileLayer(data);
        ground.setVisible(true);
        ground.setRenderType(RenderType.BACKGROUND);
        ground.setWidth(10);
        ground.setHeight(10);
        map.addLayer(ground);
        Game.world().loadEnvironment(map);

but adding the following code right before loadEnviornment() makes drawTile() function as intended.

try {map.finish(Game.class.getClassLoader().getResource("tilesheet.tsx"));} 
catch (TmxException e) {e.printStackTrace();}

I could be doing something wrong here, but wanted to check in either way.

@steffen-wilke
Copy link
Contributor

This problem is addressed by the new API I introduced with 96be92d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant