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,
        float unitsPerTileX, float unitsPerTileY) 

Source Link

Document

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

Usage

From source file:com.game.HelloWorld.java

License:Apache License

private void create_tiledMap() {
    final String path = "data/tiledmap/";
    final String mapname = "foret";

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

    this.mMap = TiledLoader.createMap(mapHandle);

    this.mAtlas = new TileAtlas(this.mMap, baseDir);

    int blockWidth = 128;
    int blockHeight = 128;

    mTileMapRenderer = new TileMapRenderer(this.mMap, this.mAtlas, blockWidth, blockHeight, 128, 128);

    for (TiledObjectGroup group : this.mMap.objectGroups) {
        for (TiledObject object : group.objects) {
            // TODO: Draw sprites where objects occur

            positionBoites.add(new Sphere(new Vector3(object.x, object.y, 0), 50));
            System.out.println("Object " + object.name + " x,y = " + object.x + "," + object.y
                    + " width,height = " + object.width + "," + object.height);
        }/*from   ww  w  . j  ava2  s . com*/
    }

    // float aspectRatio = (float)Gdx.graphics.getWidth() /
    // (float)Gdx.graphics.getHeight();
    // mCam = new OrthographicCamera(100f * aspectRatio, 100f);

    // mCam.position.set(mTileMapRenderer.getMapWidthUnits() / 2,
    // mTileMapRenderer.getMapHeightUnits() / 2, 0);

    // camController = new OrthoCamController(cam);
    // Gdx.input.setInputProcessor(camController);

    // mMaxCamPosition.set(mTileMapRenderer.getMapWidthUnits(),
    // mTileMapRenderer.getMapHeightUnits());
}