Search in sources :

Example 1 with IsometricTiledMapRenderer

use of com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer in project libgdx by libgdx.

the class TiledMapAssetManagerTest method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 10, 10);
    camera.zoom = 2;
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    assetManager = new AssetManager();
    assetManager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
    assetManager.load("data/maps/tiled/isometric_grass_and_water.tmx", TiledMap.class);
    assetManager.finishLoading();
    map = assetManager.get("data/maps/tiled/isometric_grass_and_water.tmx");
    renderer = new IsometricTiledMapRenderer(map, 1f / 64f);
    String mapCustomValue = map.getProperties().get(MAP_PROPERTY_NAME, String.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + MAP_PROPERTY_NAME + ", Value : " + mapCustomValue);
    if (!MAP_PROPERTY_VALUE.equals(mapCustomValue)) {
        throw new RuntimeException("Failed to get map properties");
    }
    boolean boolCustomValue = map.getProperties().get(BOOL_PROPERTY_NAME, Boolean.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + BOOL_PROPERTY_NAME + ", Value : " + boolCustomValue);
    if (boolCustomValue != BOOL_PROPERTY_VALUE) {
        throw new RuntimeException("Failed to get boolean map properties");
    }
    int intCustomValue = map.getProperties().get(INT_PROPERTY_NAME, Integer.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + INT_PROPERTY_NAME + ", Value : " + intCustomValue);
    if (intCustomValue != INT_PROPERTY_VALUE) {
        throw new RuntimeException("Failed to get int map properties");
    }
    float floatCustomValue = map.getProperties().get(FLOAT_PROPERTY_NAME, Float.class);
    Gdx.app.log("TiledMapAssetManagerTest", "Property : " + FLOAT_PROPERTY_NAME + ", Value : " + floatCustomValue);
    if (floatCustomValue != FLOAT_PROPERTY_VALUE) {
        throw new RuntimeException("Failed to get float map properties");
    }
    TiledMapTileSet tileset = map.getTileSets().getTileSet(0);
    String tilesetCustomValue = tileset.getProperties().get(TILESET_PROPERTY_NAME, String.class);
    if (!TILESET_PROPERTY_VALUE.equals(tilesetCustomValue)) {
        throw new RuntimeException("Failed to get tileset properties");
    }
    TiledMapTile tile = tileset.getTile(1);
    String tileCustomValue = tile.getProperties().get(TILE_PROPERTY_NAME, String.class);
    if (!TILE_PROPERTY_VALUE.equals(tileCustomValue)) {
        throw new RuntimeException("Failed to get tile properties");
    }
    MapLayer layer = map.getLayers().get(0);
    String layerCustomValue = layer.getProperties().get(LAYER_PROPERTY_NAME, String.class);
    if (!LAYER_PROPERTY_VALUE.equals(layerCustomValue)) {
        throw new RuntimeException("Failed to get layer properties");
    }
}
Also used : TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) AssetManager(com.badlogic.gdx.assets.AssetManager) TiledMapTileSet(com.badlogic.gdx.maps.tiled.TiledMapTileSet) MapLayer(com.badlogic.gdx.maps.MapLayer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) IsometricTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 2 with IsometricTiledMapRenderer

use of com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer in project libgdx by libgdx.

the class TiledMapLayerOffsetTest method render.

@Override
public void render() {
    if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)) {
        if (mapType != 0) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 0;
            map = assetManager.get(MAP_ORTHO);
            renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)) {
        if (mapType != 1) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 1;
            map = assetManager.get(MAP_ORTHO);
            renderer = new OrthoCachedTiledMapRenderer(map, 1f / 32f);
            ((OrthoCachedTiledMapRenderer) renderer).setBlending(true);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) {
        if (mapType != 2) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 2;
            map = assetManager.get(MAP_ISO);
            renderer = new IsometricTiledMapRenderer(map, 1f / 48f);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_4)) {
        if (mapType != 3) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 3;
            map = assetManager.get(MAP_ISO_STAG);
            renderer = new IsometricStaggeredTiledMapRenderer(map, 1f / 48f);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_5)) {
        if (mapType != 4) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 4;
            map = assetManager.get(MAP_HEX_X);
            renderer = new HexagonalTiledMapRenderer(map, 1f / 48f);
        }
    } else if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_6)) {
        if (mapType != 5) {
            if (renderer instanceof Disposable)
                ((Disposable) renderer).dispose();
            mapType = 5;
            map = assetManager.get(MAP_HEX_Y);
            renderer = new HexagonalTiledMapRenderer(map, 1f / 48f);
        }
    }
    Gdx.gl.glClearColor(100f / 255f, 100f / 255f, 250f / 255f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();
    // add margin to view bounds so it is easy to see any issues with clipping, calculated same way as
    // BatchTiledMapRenderer#setView (OrthographicCamera)
    final float margin = 3;
    final float width = camera.viewportWidth * camera.zoom - margin * 2;
    final float height = camera.viewportHeight * camera.zoom - margin * 2;
    final float w = width * Math.abs(camera.up.y) + height * Math.abs(camera.up.x);
    final float h = height * Math.abs(camera.up.y) + width * Math.abs(camera.up.x);
    final float x = camera.position.x - w / 2;
    final float y = camera.position.y - h / 2;
    renderer.setView(camera.combined, x, y, w, h);
    renderer.render();
    shapeRenderer.setProjectionMatrix(camera.combined);
    shapeRenderer.begin(ShapeType.Line);
    shapeRenderer.setColor(Color.RED);
    shapeRenderer.rect(x, y, w, h);
    shapeRenderer.end();
    batch.begin();
    font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
    font.draw(batch, "Switch type with 1-6", Gdx.graphics.getHeight() - 100, 50);
    font.draw(batch, renderer.getClass().getSimpleName(), Gdx.graphics.getHeight() - 100, 20);
    batch.end();
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) IsometricTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer) IsometricStaggeredTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.IsometricStaggeredTiledMapRenderer) OrthoCachedTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthoCachedTiledMapRenderer) HexagonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer)

Example 3 with IsometricTiledMapRenderer

use of com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer in project libgdx by libgdx.

the class TiledMapModifiedExternalTilesetTest method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 10, 10);
    camera.position.set(10.0f, 2.5f, 0.0f);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    // These two maps should appear identical -- a ring of grass with water inside and out.
    // The original is correct, without the bug fix to TiledMapTileSets.java that acompanies
    // this test, the latter appears as all grass.
    //		map = new TmxMapLoader().load("data/maps/tiled/external-tilesets/test_original.tmx");
    map = new TmxMapLoader().load("data/maps/tiled/external-tilesets/test_extended.tmx");
    renderer = new IsometricTiledMapRenderer(map, 1f / 32f);
}
Also used : TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) IsometricTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Aggregations

IsometricTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer)3 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)2 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)1 MapLayer (com.badlogic.gdx.maps.MapLayer)1 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)1 TiledMapTileSet (com.badlogic.gdx.maps.tiled.TiledMapTileSet)1 HexagonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer)1 IsometricStaggeredTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.IsometricStaggeredTiledMapRenderer)1 OrthoCachedTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthoCachedTiledMapRenderer)1 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)1 Disposable (com.badlogic.gdx.utils.Disposable)1