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();
}
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();
}
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);
}
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);
}
}
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();
}
Aggregations