Example usage for com.badlogic.gdx.maps.tiled TmxMapLoader TmxMapLoader

List of usage examples for com.badlogic.gdx.maps.tiled TmxMapLoader TmxMapLoader

Introduction

In this page you can find the example usage for com.badlogic.gdx.maps.tiled TmxMapLoader TmxMapLoader.

Prototype

public TmxMapLoader() 

Source Link

Usage

From source file:MyGdxGame.java

License:Apache License

@Override
public void create() {
    // load the koala frames, split them, and assign them to Animations
    koalaTexture = new Texture("koalio.png");
    TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0];
    stand = new Animation(0, regions[0]);
    jump = new Animation(0, regions[1]);
    walk = new Animation(0.15f, regions[2], regions[3], regions[4]);
    walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);

    // figure out the width and height of the koala for collision
    // detection and rendering by converting a koala frames pixel
    // size into world units (1 unit == 16 pixels)
    Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth();
    Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight();

    // load the map, set the unit scale to 1/16 (1 unit == 16 pixels)
    map = new TmxMapLoader().load("level1.tmx");
    renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f);

    // create an orthographic camera, shows us 30x20 units of the world
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 30, 20);/*from   w w  w .j a  v  a  2s .com*/
    camera.update();

    // create the Koala we want to move around the world
    koala = new Koala();
    koala.position.set(20, 20);
}

From source file:com.agateau.pixelwheels.map.Track.java

License:Open Source License

public void init() {
    if (mMap != null) {
        return;/*from   w  w  w  .  j a  v a 2  s .c om*/
    }
    TmxMapLoader loader = new TmxMapLoader();
    mMap = loader.load(Gdx.files.internal("maps/" + mId + ".tmx").path());
    mMaterialForTileId = computeMaterialForTileId();
    findSpecialTileIds();
    findLayers();
    readBorders();

    mTileWidth = Constants.UNIT_FOR_PIXEL * mBackgroundLayers.get(0).getTileWidth();
    mTileHeight = Constants.UNIT_FOR_PIXEL * mBackgroundLayers.get(0).getTileHeight();

    mLapPositionTable = LapPositionTableIO.load(mMap);
    readWaypoints();

    String bgColorText = mMap.getProperties().get("backgroundcolor", "#808080", String.class);
    bgColorText = bgColorText.substring(1); // Skip leading '#'
    mBackgroundColor = Color.valueOf(bgColorText);
}

From source file:com.agateau.pixelwheels.tools.LapPositionTableGenerator.java

License:Apache License

public static void generateTable(FileHandle tmxFile, FileHandle tableFile) {
    TiledMap map = new TmxMapLoader().load(tmxFile.path());
    LapPositionTable table = LapPositionTableIO.load(map);

    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0);
    int width = layer.getWidth() * ((int) layer.getTileWidth());
    int height = layer.getHeight() * ((int) layer.getTileHeight());

    Pixmap pixmap = LapPositionTableIO.createPixmap(table, width, height);
    PixmapIO.writePNG(tableFile, pixmap);
}

From source file:com.agateau.pixelwheels.tools.MapScreenshotGenerator.java

License:Apache License

private static Pixmap generateScreenshot(FileHandle tmxFile) {
    TiledMap map = new TmxMapLoader().load(tmxFile.path());
    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0);
    int mapWidth = (int) (layer.getWidth() * layer.getTileWidth());
    int mapHeight = (int) (layer.getHeight() * layer.getTileHeight());

    FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGB888, mapWidth, mapHeight, false /* hasDepth */);
    OrthogonalTiledMapRenderer renderer = new OrthogonalTiledMapRenderer(map);

    OrthographicCamera camera = new OrthographicCamera();
    camera.setToOrtho(true /* yDown */, mapWidth, mapHeight);
    renderer.setView(camera);//from  w  w  w .  ja v a 2  s  .c o m

    fbo.begin();
    renderer.render();

    return ScreenUtils.getFrameBufferPixmap(0, 0, mapWidth, mapHeight);
}

From source file:com.badlogic.gdx.tests.superkoalio.SuperKoalio.java

License:Apache License

@Override
public void create() {
    // load the koala frames, split them, and assign them to Animations
    koalaTexture = new Texture("data/maps/tiled/super-koalio/koalio.png");
    TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0];
    stand = new Animation(0, regions[0]);
    jump = new Animation(0, regions[1]);
    walk = new Animation(0.15f, regions[2], regions[3], regions[4]);
    walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);

    // figure out the width and height of the koala for collision
    // detection and rendering by converting a koala frames pixel
    // size into world units (1 unit == 16 pixels)
    Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth();
    Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight();

    // load the map, set the unit scale to 1/16 (1 unit == 16 pixels)
    map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx");
    renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f);

    // create an orthographic camera, shows us 30x20 units of the world
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 30, 20);//from  www.  j  a v  a2  s  .  c o m
    camera.update();

    // create the Koala we want to move around the world
    koala = new Koala();
    koala.position.set(20, 20);
}

From source file:com.barconr.games.marblegame.Assets.java

License:Apache License

public static void load() {
    gameAtlas = new TextureAtlas(Gdx.files.internal("gfx/marble.pack"));
    marble = new TextureRegion(gameAtlas.findRegion("marb"));
    mazemap = new TmxMapLoader().load("tiles/mg.tmx");
    //      mazemap = new TmxMapLoader().load("tiles/test pattern.tmx");
    //new TmxMapLoader().lo

}

From source file:com.battleforbronze.game.Screens.WorldRenderer.java

public WorldRenderer(Player1Hand h, Player2Hand h2, HUD p1HUD, HUD p2HUD, HUD turnNew) {
    p1Health = 20;/*from  w w  w .  j a va2 s . c om*/
    p2Health = 20;
    cardOnFieldP1 = 0;
    RedTilesOnMapP1 = false;
    RedTilesOnMapP2 = false;
    highLightP1 = false;
    highLightP2 = false;
    p1OnFieldCards = new Array<Card>();
    p2OnFieldCards = new Array<Card>();
    p1OnFieldXY = new Array<OnField>();
    p2OnFieldXY = new Array<OnField>();
    playerOneHUD = p1HUD;
    playerTwoHUD = p2HUD;
    checkTurn = turnNew;
    cardSelected = false;
    menutime = true;
    instructiontime = false;
    gametime = false;
    playCard = new Card();
    instructions = new Texture("instructions.png");
    menu = new Texture("menu.png");
    p1Turn = new Texture("turnP1.png");
    p2Turn = new Texture("turnP2.png");
    border = new Texture("border.png");
    manaUsed = new Texture("manaUsed.png");
    map = new TmxMapLoader().load("map.tmx");
    buttonNotPressed = new Texture("button_notpressed.png");
    buttonPressed = new Texture("button_pressed.png");
    mana = new Texture("mana.png");
    clicked = new Cell();
    afterClick = new Cell();
    checkCell = new Cell();
    placeTile = new Cell();
    deckOne = new Deck1();
    deckTwo = new Deck2();
    click = new Vector3();
    deckThree = new Deck3();
    hand = h;
    hand2 = h2;
    gameSet = map.getTileSets().getTileSet("tiles");
    path = (TiledMapTileLayer) map.getLayers().get("path");
    base = (TiledMapTileLayer) map.getLayers().get("base");
    card = new Texture("Card.png");
    font = new BitmapFont();
    HealthP1 = new BitmapFont();
    HealthP2 = new BitmapFont();
    int mapWidth = map.getProperties().get("width", Integer.class);
    int mapHeight = map.getProperties().get("height", Integer.class);

    attkNum1 = new Texture("Numbers/Attack/A1.png");
    attkNum2 = new Texture("Numbers/Attack/A2.png");
    attkNum3 = new Texture("Numbers/Attack/A3.png");
    attkNum4 = new Texture("Numbers/Attack/A4.png");
    attkNum5 = new Texture("Numbers/Attack/A5.png");
    attkNum6 = new Texture("Numbers/Attack/A6.png");
    attkNum7 = new Texture("Numbers/Attack/A7.png");
    attkNum8 = new Texture("Numbers/Attack/A8.png");
    attkNum9 = new Texture("Numbers/Attack/A9.png");

    defNum1 = new Texture("Numbers/Defence/D1.png");
    defNum2 = new Texture("Numbers/Defence/D2.png");
    defNum3 = new Texture("Numbers/Defence/D3.png");
    defNum4 = new Texture("Numbers/Defence/D4.png");
    defNum5 = new Texture("Numbers/Defence/D5.png");
    defNum6 = new Texture("Numbers/Defence/D6.png");
    defNum7 = new Texture("Numbers/Defence/D7.png");
    defNum8 = new Texture("Numbers/Defence/D8.png");
    defNum9 = new Texture("Numbers/Defence/D9.png");

    frcNum1 = new Texture("Numbers/Force/F1.png");
    frcNum2 = new Texture("Numbers/Force/F2.png");
    frcNum3 = new Texture("Numbers/Force/F3.png");
    frcNum4 = new Texture("Numbers/Force/F4.png");
    frcNum5 = new Texture("Numbers/Force/F5.png");
    frcNum6 = new Texture("Numbers/Force/F6.png");
    frcNum7 = new Texture("Numbers/Force/F7.png");
    frcNum8 = new Texture("Numbers/Force/F8.png");
    frcNum9 = new Texture("Numbers/Force/F9.png");

    font.setColor(Color.BLACK);

    //        picture = new Texture("Player1.png");
    camera = new OrthographicCamera();
    guiCam = new OrthographicCamera();
    viewport = new FitViewport(V_WIDTH * 0.5f, V_HEIGHT * 0.5f, camera);
    guiViewport = new FitViewport(V_WIDTH * 0.5f, V_HEIGHT * 0.5f, guiCam);
    batch = new SpriteBatch();
    render = new OrthogonalTiledMapRenderer(map, batch);

    // move the x position of the camera
    camera.position.x = 432 / 2;
    guiCam.position.x = V_WIDTH / 2;
    // move the y position of the camera
    camera.position.y = 0 + (592 / 4);
    guiCam.position.y = V_HEIGHT / 2;
    // update the camera
    camera.update();

    // loads in the images
    //AssetManager.load();
}

From source file:com.gdx.game.screens.PlayScreen.java

public PlayScreen(GdxGame game, AssetManager assetManager) {
    atlas = new TextureAtlas("Mario_and_Enemies.pack");

    this.game = game;
    this.assetManager = assetManager;
    this.gameCam = new OrthographicCamera();
    this.gamePort = new FitViewport(GdxGame.V_WIDTH / GdxGame.PPM, GdxGame.V_HEIGHT / GdxGame.PPM, gameCam);

    // create HUD
    this.hud = new Hud(game.getBatch());

    // load map and setup renderer
    this.mapLoader = new TmxMapLoader();
    this.map = mapLoader.load("level1.tmx");
    this.renderer = new OrthogonalTiledMapRenderer(this.map, 1 / GdxGame.PPM);

    this.gameCam.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0);

    this.world = new World(new Vector2(0, -10), true);
    this.box2DDebugRenderer = new Box2DDebugRenderer();

    new b2WorldCreator(world, map, this.assetManager);

    this.player = new Player(this.world, this);

    music = this.assetManager.get("audio/music/mario_music.ogg", Music.class);
    music.setLooping(true);//from w  w w .  j ava 2  s  .  c  o m
    music.play();

    world.setContactListener(new WolrdContactListener());

}

From source file:com.holotrash.lazerdeath2.lazerdeath2.java

License:Open Source License

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, w, h);/*from  w w w . j  a  va2  s  .co m*/
    camera.update();
    mapData = null;
    try {
        mapData = new Map(0, this);
    } catch (IOException e) {
        System.out.println("loading map data failed for level 0");
        e.printStackTrace();
    }
    gm = new GameMaster(this, mapData);
    initializeDudes();
    initializeEnemies();

    lastClickedCell = new Coord(-1, -1);
    highlightTiles = new HashMap<Coord, HighlightTile>();
    highlightOn = false;
    interactedTiles = new ArrayList<InteractedTile>();

    dudesTurnSprite = new Sprite(new Texture(Gdx.files.internal("gfx/dudes_turn.png")));
    enemiesTurnSprite = new Sprite(new Texture(Gdx.files.internal("gfx/enemy_turn.png")));
    this.leftStatusBox = new Sprite(new Texture(Gdx.files.internal("gfx/left_status_box.png")));
    this.rightStatusBox = new Sprite(new Texture(Gdx.files.internal("gfx/right_status_box.png")));
    this.rightStatusBoxFade = new Sprite(new Texture(Gdx.files.internal("gfx/right_status_box_fade_out.png")));
    this.defaultGlamourShot = new Sprite(new Texture(Gdx.files.internal("gfx/default_glamourshot.png")));
    this.glamourShot = defaultGlamourShot;
    this.endTurnButton = new Sprite(new Texture(Gdx.files.internal("gfx/end_turn.png")));
    this.attackButton = new Sprite(new Texture(Gdx.files.internal("gfx/attack_button.png")));
    this.exitGameButton = new Sprite(new Texture(Gdx.files.internal("gfx/exit_game.png")));
    this.menuButton = new Sprite(new Texture(Gdx.files.internal("gfx/menu_button.png")));
    this.unitCursor = new Sprite(new Texture(Gdx.files.internal("gfx/unit_cursor.png")));
    tiledMap = new TmxMapLoader().load("gfx/" + mapData.tmxFileName + ".tmx");
    spriteBatch = new SpriteBatch();
    highlightBatch = new SpriteBatch();
    tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap, spriteBatch);
    Gdx.input.setInputProcessor(this);
    menuDialog = new MenuDialog(this);
    dialogBox = new DialogBox();
    dialogFont = new BitmapFont(Gdx.files.internal("fonts/bank.fnt"));
    uiFont = new BitmapFont(Gdx.files.internal("fonts/hack.fnt"));
    layout = new GlyphLayout();
    this.ynDialog = new SimpleBooleanDialog("Will you eat my shit?", "Answer immediately!", "", "Jeah!",
            "Nah...");
    gm.showLevelStartDialog();
    selectedUnit = null;

    currentUnitStats = new ArrayList<String>();
    currentUnitStats.add("SELECT A UNIT TO");
    currentUnitStats.add("BEGIN PERPETUATING");
    currentUnitStats.add("THE CYCLE OF");
    currentUnitStats.add("VIOLENCE");
    currentUnitStats.add("...");

    uiConsole = new ArrayDeque<String>();
    uiConsole.push("Battle start...");

    this.screenOrigin = new Vector3(0, 768, 0);
    this.screenOrigin = camera.unproject(this.screenOrigin);

}

From source file:com.johnberg.spacebooty.Play.java

License:Apache License

@Override
public void show() {
    batch = new SpriteBatch();

    camera = new OrthographicCamera();

    tiledMap = new TmxMapLoader().load("fortress.tmx");

    //Create the Game Layer
    gameLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Game");

    //Create the Marker layer
    markerLayer = (TiledMapTileLayer) tiledMap.getLayers().get("Markers");

    cell = new Array<TiledMapTileLayer.Cell>();
    cell.add(markerLayer.getCell(2, 3));
    cell.add(markerLayer.getCell(6, 3));
    cell.add(markerLayer.getCell(8, 3));
    cell.add(markerLayer.getCell(12, 3));
    cell.add(markerLayer.getCell(1, 14));
    cell.add(markerLayer.getCell(2, 14));
    cell.add(markerLayer.getCell(6, 14));
    cell.add(markerLayer.getCell(8, 14));
    cell.add(markerLayer.getCell(12, 14));
    cell.add(markerLayer.getCell(13, 14));

    //Create the renderer
    float unitScale = 1f / 48f;
    renderer = new OrthogonalTiledMapRenderer(tiledMap, unitScale);

    tex = new Texture("background.png");
    background = new Sprite(tex);
}