Search in sources :

Example 1 with MapLayer

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

the class BatchTiledMapRenderer method render.

@Override
public void render() {
    beginRender();
    for (MapLayer layer : map.getLayers()) {
        if (layer.isVisible()) {
            if (layer instanceof TiledMapTileLayer) {
                renderTileLayer((TiledMapTileLayer) layer);
            } else if (layer instanceof TiledMapImageLayer) {
                renderImageLayer((TiledMapImageLayer) layer);
            } else {
                renderObjects(layer);
            }
        }
    }
    endRender();
}
Also used : TiledMapImageLayer(com.badlogic.gdx.maps.tiled.TiledMapImageLayer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) MapLayer(com.badlogic.gdx.maps.MapLayer)

Example 2 with MapLayer

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

the class BatchTiledMapRenderer method render.

@Override
public void render(int[] layers) {
    beginRender();
    for (int layerIdx : layers) {
        MapLayer layer = map.getLayers().get(layerIdx);
        if (layer.isVisible()) {
            if (layer instanceof TiledMapTileLayer) {
                renderTileLayer((TiledMapTileLayer) layer);
            } else if (layer instanceof TiledMapImageLayer) {
                renderImageLayer((TiledMapImageLayer) layer);
            } else {
                renderObjects(layer);
            }
        }
    }
    endRender();
}
Also used : TiledMapImageLayer(com.badlogic.gdx.maps.tiled.TiledMapImageLayer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) MapLayer(com.badlogic.gdx.maps.MapLayer)

Example 3 with MapLayer

use of com.badlogic.gdx.maps.MapLayer 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 4 with MapLayer

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

the class BaseTmxMapLoader method loadObjectGroup.

protected void loadObjectGroup(TiledMap map, Element element) {
    if (element.getName().equals("objectgroup")) {
        String name = element.getAttribute("name", null);
        MapLayer layer = new MapLayer();
        layer.setName(name);
        Element properties = element.getChildByName("properties");
        if (properties != null) {
            loadProperties(layer.getProperties(), properties);
        }
        for (Element objectElement : element.getChildrenByName("object")) {
            loadObject(map, layer, objectElement);
        }
        map.getLayers().add(layer);
    }
}
Also used : MapLayer(com.badlogic.gdx.maps.MapLayer) Element(com.badlogic.gdx.utils.XmlReader.Element)

Example 5 with MapLayer

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

the class TiledMapObjectLoadingTest method render.

@Override
public void render() {
    Gdx.gl.glClearColor(0.55f, 0.55f, 0.55f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();
    shapeRenderer.setProjectionMatrix(camera.combined);
    batch.setProjectionMatrix(camera.combined);
    shapeRenderer.setColor(Color.BLUE);
    Gdx.gl20.glLineWidth(2);
    MapLayer layer = map.getLayers().get("Objects");
    AnimatedTiledMapTile.updateAnimationBaseTime();
    for (MapObject mapObject : layer.getObjects()) {
        if (mapObject instanceof TiledMapTileMapObject) {
            batch.begin();
            TiledMapTileMapObject tmtObject = (TiledMapTileMapObject) mapObject;
            TextureRegion textureRegion = tmtObject.getTile().getTextureRegion();
            // TilEd rotation is clockwise, we need counter-clockwise.
            float rotation = -tmtObject.getRotation();
            float scaleX = tmtObject.getScaleX();
            float scaleY = tmtObject.getScaleY();
            float xPos = tmtObject.getX();
            float yPos = tmtObject.getY();
            textureRegion.flip(tmtObject.isFlipHorizontally(), tmtObject.isFlipVertically());
            batch.draw(textureRegion, xPos, yPos, tmtObject.getOriginX() * scaleX, tmtObject.getOriginY() * scaleY, textureRegion.getRegionWidth() * scaleX, textureRegion.getRegionHeight() * scaleY, 1f, 1f, rotation);
            // We flip back to the original state.
            textureRegion.flip(tmtObject.isFlipHorizontally(), tmtObject.isFlipVertically());
            batch.end();
        } else if (mapObject instanceof EllipseMapObject) {
            shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
            Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
            shapeRenderer.ellipse(ellipse.x, ellipse.y, ellipse.width, ellipse.height);
            shapeRenderer.end();
        } else if (mapObject instanceof RectangleMapObject) {
            shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
            Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();
            shapeRenderer.rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
            shapeRenderer.end();
        } else if (mapObject instanceof PolygonMapObject) {
            shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
            Polygon polygon = ((PolygonMapObject) mapObject).getPolygon();
            shapeRenderer.polygon(polygon.getTransformedVertices());
            shapeRenderer.end();
        }
    }
    batch.begin();
    font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
    batch.end();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PolygonMapObject(com.badlogic.gdx.maps.objects.PolygonMapObject) Ellipse(com.badlogic.gdx.math.Ellipse) RectangleMapObject(com.badlogic.gdx.maps.objects.RectangleMapObject) MapLayer(com.badlogic.gdx.maps.MapLayer) EllipseMapObject(com.badlogic.gdx.maps.objects.EllipseMapObject) Rectangle(com.badlogic.gdx.math.Rectangle) TiledMapTileMapObject(com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject) Polygon(com.badlogic.gdx.math.Polygon) MapObject(com.badlogic.gdx.maps.MapObject) TextureMapObject(com.badlogic.gdx.maps.objects.TextureMapObject) EllipseMapObject(com.badlogic.gdx.maps.objects.EllipseMapObject) TiledMapTileMapObject(com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject) RectangleMapObject(com.badlogic.gdx.maps.objects.RectangleMapObject) PolygonMapObject(com.badlogic.gdx.maps.objects.PolygonMapObject)

Aggregations

MapLayer (com.badlogic.gdx.maps.MapLayer)11 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)6 TiledMapImageLayer (com.badlogic.gdx.maps.tiled.TiledMapImageLayer)4 MapLayers (com.badlogic.gdx.maps.MapLayers)2 MapObject (com.badlogic.gdx.maps.MapObject)2 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 MapObjects (com.badlogic.gdx.maps.MapObjects)1 EllipseMapObject (com.badlogic.gdx.maps.objects.EllipseMapObject)1 PolygonMapObject (com.badlogic.gdx.maps.objects.PolygonMapObject)1 RectangleMapObject (com.badlogic.gdx.maps.objects.RectangleMapObject)1 TextureMapObject (com.badlogic.gdx.maps.objects.TextureMapObject)1 Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)1 TiledMapTileSet (com.badlogic.gdx.maps.tiled.TiledMapTileSet)1 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)1