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