Search in sources :

Example 1 with MapLayers

use of com.badlogic.gdx.maps.MapLayers in project libgdx by libgdx.

the class OrthoCachedTiledMapRenderer method render.

@Override
public void render(int[] layers) {
    if (!cached) {
        cached = true;
        count = 0;
        spriteCache.clear();
        final float extraWidth = viewBounds.width * overCache;
        final float extraHeight = viewBounds.height * overCache;
        cacheBounds.x = viewBounds.x - extraWidth;
        cacheBounds.y = viewBounds.y - extraHeight;
        cacheBounds.width = viewBounds.width + extraWidth * 2;
        cacheBounds.height = viewBounds.height + extraHeight * 2;
        for (MapLayer layer : map.getLayers()) {
            spriteCache.beginCache();
            if (layer instanceof TiledMapTileLayer) {
                renderTileLayer((TiledMapTileLayer) layer);
            } else if (layer instanceof TiledMapImageLayer) {
                renderImageLayer((TiledMapImageLayer) layer);
            }
            spriteCache.endCache();
        }
    }
    if (blending) {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
    spriteCache.begin();
    MapLayers mapLayers = map.getLayers();
    for (int i : layers) {
        MapLayer layer = mapLayers.get(i);
        if (layer.isVisible()) {
            spriteCache.draw(i);
            renderObjects(layer);
        }
    }
    spriteCache.end();
    if (blending)
        Gdx.gl.glDisable(GL20.GL_BLEND);
}
Also used : TiledMapImageLayer(com.badlogic.gdx.maps.tiled.TiledMapImageLayer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) MapLayer(com.badlogic.gdx.maps.MapLayer) MapLayers(com.badlogic.gdx.maps.MapLayers)

Example 2 with MapLayers

use of com.badlogic.gdx.maps.MapLayers in project libgdx by libgdx.

the class TiledMapBench method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 320, 320);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    {
        tiles = new Texture(Gdx.files.internal("data/maps/tiled/tiles.png"));
        TextureRegion[][] splitTiles = TextureRegion.split(tiles, 32, 32);
        map = new TiledMap();
        MapLayers layers = map.getLayers();
        for (int l = 0; l < 20; l++) {
            TiledMapTileLayer layer = new TiledMapTileLayer(150, 100, 32, 32);
            for (int x = 0; x < 150; x++) {
                for (int y = 0; y < 100; y++) {
                    int ty = (int) (Math.random() * splitTiles.length);
                    int tx = (int) (Math.random() * splitTiles[ty].length);
                    Cell cell = new Cell();
                    cell.setTile(new StaticTiledMapTile(splitTiles[ty][tx]));
                    layer.setCell(x, y, cell);
                }
            }
            layers.add(layer);
        }
    }
    renderer = new OrthogonalTiledMapRenderer(map);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) MapLayers(com.badlogic.gdx.maps.MapLayers)

Example 3 with MapLayers

use of com.badlogic.gdx.maps.MapLayers in project libgdx by libgdx.

the class HexagonalTiledMapTest method create.

@Override
public void create() {
    super.create();
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 480, 480);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    hexture = new Texture(Gdx.files.internal("data/maps/tiled/hex/hexes.png"));
    TextureRegion[][] hexes = TextureRegion.split(hexture, 112, 97);
    map = new TiledMap();
    MapLayers layers = map.getLayers();
    TiledMapTile[] tiles = new TiledMapTile[3];
    tiles[0] = new StaticTiledMapTile(new TextureRegion(hexes[0][0]));
    tiles[1] = new StaticTiledMapTile(new TextureRegion(hexes[0][1]));
    tiles[2] = new StaticTiledMapTile(new TextureRegion(hexes[1][0]));
    for (int l = 0; l < 1; l++) {
        TiledMapTileLayer layer = new TiledMapTileLayer(45, 30, 112, 97);
        for (int y = 0; y < 30; y++) {
            for (int x = 0; x < 45; x++) {
                int id = (int) (Math.random() * 3);
                Cell cell = new Cell();
                cell.setTile(tiles[id]);
                layer.setCell(x, y, cell);
            }
        }
        layers.add(layer);
    }
    renderer = new HexagonalTiledMapRenderer(map);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) HexagonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) MapLayers(com.badlogic.gdx.maps.MapLayers)

Example 4 with MapLayers

use of com.badlogic.gdx.maps.MapLayers in project libgdx by libgdx.

the class OrthoCachedTiledMapRenderer method render.

@Override
public void render() {
    if (!cached) {
        cached = true;
        count = 0;
        spriteCache.clear();
        final float extraWidth = viewBounds.width * overCache;
        final float extraHeight = viewBounds.height * overCache;
        cacheBounds.x = viewBounds.x - extraWidth;
        cacheBounds.y = viewBounds.y - extraHeight;
        cacheBounds.width = viewBounds.width + extraWidth * 2;
        cacheBounds.height = viewBounds.height + extraHeight * 2;
        for (MapLayer layer : map.getLayers()) {
            spriteCache.beginCache();
            if (layer instanceof TiledMapTileLayer) {
                renderTileLayer((TiledMapTileLayer) layer);
            } else if (layer instanceof TiledMapImageLayer) {
                renderImageLayer((TiledMapImageLayer) layer);
            }
            spriteCache.endCache();
        }
    }
    if (blending) {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
    spriteCache.begin();
    MapLayers mapLayers = map.getLayers();
    for (int i = 0, j = mapLayers.getCount(); i < j; i++) {
        MapLayer layer = mapLayers.get(i);
        if (layer.isVisible()) {
            spriteCache.draw(i);
            renderObjects(layer);
        }
    }
    spriteCache.end();
    if (blending)
        Gdx.gl.glDisable(GL20.GL_BLEND);
}
Also used : TiledMapImageLayer(com.badlogic.gdx.maps.tiled.TiledMapImageLayer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) MapLayer(com.badlogic.gdx.maps.MapLayer) MapLayers(com.badlogic.gdx.maps.MapLayers)

Aggregations

MapLayers (com.badlogic.gdx.maps.MapLayers)4 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)4 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 Texture (com.badlogic.gdx.graphics.Texture)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 MapLayer (com.badlogic.gdx.maps.MapLayer)2 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)2 TiledMapImageLayer (com.badlogic.gdx.maps.tiled.TiledMapImageLayer)2 Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)2 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)2 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)1 HexagonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.HexagonalTiledMapRenderer)1 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)1