Example usage for com.badlogic.gdx.graphics.g2d.tiled TileMapRenderer TileMapRenderer

List of usage examples for com.badlogic.gdx.graphics.g2d.tiled TileMapRenderer TileMapRenderer

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d.tiled TileMapRenderer TileMapRenderer.

Prototype

public TileMapRenderer(TiledMap map, TileAtlas atlas, int tilesPerBlockX, int tilesPerBlockY) 

Source Link

Document

A renderer for static tile maps backed with a Sprite Cache.

Usage

From source file:com.altportalgames.colorrain.utils.TiledMapHelper.java

License:Apache License

/**
 * Loads the requested tmx map file in to the object, sets up the camera and
 * controller./*w  w w  . j a  va 2s.  co m*/
 * 
 * @param tmxFile
 */
public void loadMap() {
    final String path = "data/tramp/output/";
    final String mapname = "tramp gzip";

    FileHandle mapHandle = Gdx.files.internal(path + mapname + ".tmx");
    FileHandle baseDir = Gdx.files.internal(path);

    //map = TiledLoader.createMap(Gdx.files.internal(tmxFile));
    map = TiledLoader.createMap(mapHandle);
    int blockWidth = 10;
    int blockHeight = 15;
    tileAtlas = new TileAtlas(map, baseDir);

    tiledMapRenderer = new TileMapRenderer(map, tileAtlas, blockWidth, blockWidth);

    camera = new OrthographicCamera(320, 480);

    camera.position.set(map.width * map.tileWidth / 2, map.height * map.tileHeight / 2, 0);
}

From source file:com.avechados.main.TiledMapHelper.java

License:Apache License

/**
 * Loads the requested tmx map file in to the helper.
 * /*w w w.ja  va  2s.  c  o  m*/
 * @param tmxFile
 */
public void loadMap(String tmxFile) {
    if (packFileDirectory == null) {
        throw new IllegalStateException("loadMap() called out of sequence");
    }

    map = TiledLoader.createMap(Gdx.files.internal(tmxFile));
    tileAtlas = new TileAtlas(map, packFileDirectory);

    tileMapRenderer = new TileMapRenderer(map, tileAtlas, 16, 16);
}

From source file:com.baldwin.libgdx.commons.SimpleTiledMapHelper.java

License:Apache License

/**
 * Loads the requested tmx map file in to the helper.
 * /*  w  w w.j  av  a2s.  c  om*/
 * @param tmxFile
 */
public void loadMap(String tmxFile) {
    if (resourceDirectory == null) {
        throw new IllegalStateException("loadMap() called out of sequence");
    }

    map = TiledLoader.createMap(Gdx.files.internal(tmxFile));
    tileAtlas = new SimpleTileAtlas(map, resourceDirectory);

    tileMapRenderer = new TileMapRenderer(map, tileAtlas, 16, 16);
}

From source file:com.rabrant.bashnbump.TiledMapHelper.java

License:Apache License

/**
 * Loads the requested tmx map file in to the helper.
 * /*from   w ww.  j  av a  2 s.c o m*/
 * @param tmxFile
 */
public void loadMap(String tmxFile) {
    if (packFileDirectory == null) {
        throw new IllegalStateException("loadMap() called out of sequence");
    }

    map = TiledLoader.createMap(Gdx.files.internal(tmxFile));
    tileAtlas = new TileAtlas(map, packFileDirectory);

    tileMapRenderer = new TileMapRenderer(map, tileAtlas, 32, 16);
}

From source file:com.raimsoft.dungeonball.tiled.TiledMapHelper2.java

License:Apache License

/**
 * tmx? . /*from w  w w .jav  a 2s .  c  o  m*/
 * @param tmxFile
 */
public void loadMap(String tmxFile) {
    if (packFileHandle == null)
        throw new IllegalStateException("loadMap() called out of sequence");

    map = TiledLoader.createMap(Gdx.files.internal(tmxFile));
    tileAtlas = new TileAtlas(map, packFileHandle);

    tiledMapRenderer = new TileMapRenderer(map, tileAtlas, Gdx.graphics.getWidth() / 4,
            Gdx.graphics.getHeight() / 4);

    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    camera.position.set(0, 0, 0);
}

From source file:com.sertaogames.cactus2d.components.TileMapComponent.java

License:Open Source License

public TileMapComponent(String path, String filename) {
    baseDir = Gdx.files.internal(path);//from w w w .  j  a  v a  2 s .  c  om
    file = Gdx.files.internal(path + filename);
    //renderer = GCoreApplication.assetMgr.get(path+filename, TileMapRenderer.class);
    tilemap = TiledLoader.createMap(file);
    //tilemap = renderer.getMap();

    atlas = new MyTileAtlas(tilemap, path);
    renderer = new TileMapRenderer(tilemap, atlas, 16, 16);

}

From source file:de.philweb.bubblr.TiledMapHelper.java

License:Apache License

/**
 * Loads the requested tmx map file in to the helper.
 * //from ww w  .  ja va2s.  c o m
 * @param tmxFile
 */
public void loadMap(String tmxFile) {
    if (packFileDirectory == null) {
        throw new IllegalStateException("loadMap() called out of sequence");
    }

    map = TiledLoader.createMap(Gdx.files.internal(tmxFile));
    tileAtlas = new TileAtlas(map, packFileDirectory);

    //      tileMapRenderer = new TileMapRenderer(map, tileAtlas, 16, 16);         // wofr stehen 16, 16 : The tilesPerBlockX and tilesPerBlockY parameters will need to be adjusted for best performance. Smaller values will cull more precisely, but result in longer loading times. Larger values result in shorter loading times, but will cull less precisely. 
    tileMapRenderer = new TileMapRenderer(map, tileAtlas, WorldRenderer.tiles_horizontally,
            WorldRenderer.tiles_vertically);
}

From source file:net.k3rnel.unsealed.screens.BattleScreen.java

License:Open Source License

@Override
public void show() {
    super.show();
    long time = new Date().getTime();
    Gdx.app.log(Unsealed.LOG, "Starting... ");
    if (!scriptedBattle)
        game.getMusicManager().play(UnsealedMusic.BATTLE);
    atlas = Unsealed.getInstance().getTextureAtlas();

    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started atlas in... " + time);
    time = new Date().getTime();

    // Load the tmx file into map
    tileMap = TiledLoader.createMap(Gdx.files.internal("map-atlases/" + mapname + ".tmx"));

    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started tiledMap in... " + time);
    time = new Date().getTime();

    // Load the tiles into atlas
    tileAtlas = new TileAtlas(tileMap, Gdx.files.internal("map-atlases/"));

    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started tileAtlas in... " + time);
    time = new Date().getTime();

    // Create the renderer
    tileMapRenderer = new TileMapRenderer(tileMap, tileAtlas, tileMap.width, tileMap.height);

    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started tileMapRenderer in... " + time);
    time = new Date().getTime();

    // Create the camera
    camera = new OrthographicCamera(MENU_VIEWPORT_WIDTH, MENU_VIEWPORT_HEIGHT);
    camera.position.set(850, 1265, 0);//  www. j a  v  a2s  . com
    camera.zoom = 0.8f;
    camera.update();

    AtlasRegion atlasRegion = atlas.findRegion("battle/ui/field-3x3");
    battleoverlay = new Image(atlasRegion);
    battleoverlay.setScale(1.2f);
    battleoverlay.setX(MENU_VIEWPORT_WIDTH / 2 - (battleoverlay.getWidth() * battleoverlay.getScaleX()) / 2);
    battleoverlay.setY(MENU_VIEWPORT_HEIGHT / 2 - (battleoverlay.getHeight() * battleoverlay.getScaleY()) - 65);
    stage.addActor(battleoverlay);

    stateTime = 0;

    characters = new ArrayList<MapCharacter>();
    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started camera & overlay in... " + time);
    time = new Date().getTime();
    hud = new BattleHUD(getAtlas(), this.stage.getWidth(), stage.getHeight());
    hud.xButton.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            super.touchDown(event, x, y, pointer, button);
            buttonPress(6, true);
            Gdx.input.vibrate(10);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);
            buttonPress(6, false);
        }
    });
    hud.bButton.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            super.touchDown(event, x, y, pointer, button);
            buttonPress(7, true);
            Gdx.input.vibrate(10);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);
            buttonPress(7, false);
        }
    });

    hud.aButton.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            super.touchDown(event, x, y, pointer, button);
            buttonPress(8, true);
            Gdx.input.vibrate(10);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);
            buttonPress(8, false);
        }
    });

    hud.yButton.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            super.touchDown(event, x, y, pointer, button);
            buttonPress(9, true);
            Gdx.input.vibrate(10);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);
            buttonPress(9, false);
        }
    });
    if (Gdx.app.getType() == ApplicationType.Android || Unsealed.DEBUG == true) {
        hud.leftTrigger.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                super.touchDown(event, x, y, pointer, button);
                buttonPress(4, true);
                Gdx.input.vibrate(10);
                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                super.touchUp(event, x, y, pointer, button);
                buttonPress(4, false);
            }
        });
        hud.rightTrigger.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                super.touchDown(event, x, y, pointer, button);
                buttonPress(5, true);
                Gdx.input.vibrate(10);
                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                super.touchUp(event, x, y, pointer, button);
                buttonPress(5, false);
            }
        });

    }
    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started HUD in... " + time);
    time = new Date().getTime();
    grid = new BattleGrid(getAtlas(), this.stage.getWidth(), stage.getHeight(), 6, 3);

    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started GRID in... " + time);
    time = new Date().getTime();
    hero = new Lidia(getAtlas(), 150, 1, 1);
    hero.setGrid(1, 1);
    hero.setSkill1(new EarthSpikes(getAtlas()));
    hud.xButton.addActor(hero.getSkill1());

    hero.setSkill2(new TornadoVacuum(getAtlas()));
    hud.bButton.addActor(hero.getSkill2());

    hero.setSkill3(new FireLion(getAtlas()));
    hud.aButton.addActor(hero.getSkill3());
    grid.assignEntity(hero);

    hero.setSkill4(new ThunderClaw(getAtlas()));
    hero.setSkill5(new IceTentacle(getAtlas()));
    hero.setSkill6(new FirePunch(getAtlas()));
    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started hero in... " + time);
    time = new Date().getTime();
    if (!scriptedBattle)
        grid.spawnEnemies(bonus);
    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started spawn enemies in... " + time);
    time = new Date().getTime();
    roundLabel = new Label("Round " + round, getSkin());
    roundLabel.setX(350);
    roundLabel.setY(350);
    //        this.stage.addActor(roundLabel);

    atlasRegion = atlas.findRegion("battle/ui/continue");
    restartButton = new ImageButton(new TextureRegionDrawable(atlasRegion),
            new TextureRegionDrawable(atlasRegion));
    restartButton.setY(140);
    restartButton.setX(170);
    restartButton.setWidth(426);
    restartButton.setHeight(165);
    restartButton.setVisible(false);
    restartButton.setDisabled(true);
    restartButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent arg0, float arg1, float arg2) {
            hero = new Lidia(getAtlas(), 150, 1, 1);
            hero.setGrid(1, 1);
            hero.reset();
            hero.setSkill1(new EarthSpikes(getAtlas()));
            hero.setSkill2(new TornadoVacuum(getAtlas()));
            hero.setSkill3(new FireLion(getAtlas()));
            grid.reset();
            grid.assignEntity(hero);
            bonus = 1;
            round = 1;

            restartButton.setVisible(false);
            restartButton.setDisabled(true);
            grid.spawnEnemies(bonus);

        }
    });
    this.stage.addActor(restartButton);

    NinePatch patch = getAtlas().createPatch("maps/dialog-box");

    textBoxStyle = new StyledTable.TableStyle();
    textBoxStyle.background = new NinePatchDrawable(patch);
    textBoxStyle.font = new BitmapFont();
    textBoxStyle.padX = 8;
    textBoxStyle.padY = 4;

    dialog = new TextBox("", textBoxStyle);
    dialog.setWidth(Gdx.graphics.getWidth());
    dialog.setHeight(Gdx.graphics.getHeight() / 8);
    dialog.setVisible(false);
    time = new Date().getTime() - time;
    Gdx.app.log(Unsealed.LOG, "Started the rest in... " + time);
    time = new Date().getTime();
    hud.addActor(dialog);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, stage, hud,
            new SimpleDirectionGestureDetector(new SimpleDirectionGestureDetector.UnsealedDirectionListener() {

                @Override
                public void onUpLeft() {
                    buttonPress(0, true);

                }

                @Override
                public void onRightLeft() {
                    buttonPress(3, true);

                }

                @Override
                public void onLeftLeft() {
                    buttonPress(2, true);

                }

                @Override
                public void onDownLeft() {
                    buttonPress(1, true);

                }

                @Override
                public void onDownRight() {
                    buttonPress(7, true);
                    buttonPress(7, false);

                }

                @Override
                public void onLeftRight() {
                    buttonPress(6, true);
                    buttonPress(6, false);

                }

                @Override
                public void onRightRight() {
                    buttonPress(8, true);
                    buttonPress(8, false);

                }

                @Override
                public void onUpRight() {
                    buttonPress(9, true);
                    buttonPress(9, false);

                }

                @Override
                public void onTapLeft() {
                    buttonPress(4, true);
                    buttonPress(4, false);

                }

                @Override
                public void onTapRight() {
                    buttonPress(5, true);
                    buttonPress(5, false);

                }
            })));

}

From source file:net.k3rnel.unsealed.story.AbstractChapter.java

License:Open Source License

public void show() {
    super.show();
    act = 0;//  w ww. j ava 2s . c  o  m
    // Load the tmx file into map
    tileMap = TiledLoader.createMap(Gdx.files.internal("map-atlases/" + mapname + ".tmx"));

    // Load the tiles into atlas
    tileAtlas = new TileAtlas(tileMap, Gdx.files.internal("map-atlases/"));

    // Create the renderer
    tileMapRenderer = new TileMapRenderer(tileMap, tileAtlas, tileMap.width, tileMap.height);

    // Create the camera
    camera = new OrthographicCamera(MENU_VIEWPORT_WIDTH, MENU_VIEWPORT_HEIGHT);
    camera.position.set(this.stage.getWidth() / 2, this.stage.getHeight() / 2, 0);

    NinePatch patch = getAtlas().createPatch("maps/dialog-box");

    textBoxStyle = new StyledTable.TableStyle();
    textBoxStyle.background = new NinePatchDrawable(patch);
    textBoxStyle.font = new BitmapFont();
    textBoxStyle.padX = 8;
    textBoxStyle.padY = 4;

    characters = new ArrayList<MapCharacter>();

    stage.setCamera(camera);

    dialog = new TextBox("", textBoxStyle);
    dialog.setWidth(Gdx.graphics.getWidth());
    dialog.setHeight(Gdx.graphics.getHeight() / 4);
    dialog.setVisible(false);

    hud.addActor(dialog);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, hud));
}