Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.fortheloss.framework.tiled;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.maps.MapObject;
- import com.badlogic.gdx.maps.tiled.TiledMap;
- import com.badlogic.gdx.maps.tiled.TiledMapTile;
- import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
- import com.badlogic.gdx.maps.tiled.renderers.BatchTiledMapRenderer;
- public class OrthogonalTiledMapRenderer3 extends BatchTiledMapRenderer
- {
- public OrthogonalTiledMapRenderer3(TiledMap map)
- {
- super(map);
- }
- public OrthogonalTiledMapRenderer3(TiledMap map, SpriteBatch spriteBatch)
- {
- super(map, spriteBatch);
- }
- public OrthogonalTiledMapRenderer3(TiledMap map, float unitScale)
- {
- super(map, unitScale);
- }
- public OrthogonalTiledMapRenderer3(TiledMap map, float unitScale, SpriteBatch spriteBatch)
- {
- super(map, unitScale, spriteBatch);
- }
- @Override
- public void renderObject(MapObject object)
- {
- }
- @Override
- public void renderTileLayer(TiledMapTileLayer layer)
- {
- final int layerWidth = layer.getWidth();
- final int layerHeight = layer.getHeight();
- final float scaledTileWidth = layer.getTileWidth() * unitScale;
- final float scaledTileHeight = layer.getTileHeight() * unitScale;
- final int col1 = Math.max(0, (int)(viewBounds.x / scaledTileWidth));
- final int col2 = Math.min(layerWidth, (int)((viewBounds.x + viewBounds.width + scaledTileWidth) / scaledTileWidth));
- final int row1 = Math.max(0, (int)(viewBounds.y / scaledTileHeight));
- final int row2 = Math.min(layerHeight, (int)((viewBounds.y + viewBounds.height + scaledTileHeight) / scaledTileHeight));
- TiledMapTileLayer.Cell cell;
- TiledMapTile tile;
- for (int row = row1; row < row2; ++row)
- {
- for (int col = col1; col < col2; ++col)
- {
- cell = layer.getCell(col, row);
- if(cell == null)
- continue;
- tile = cell.getTile();
- if (tile == null)
- continue;
- spriteBatch.draw(tile.getTextureRegion(), col * scaledTileWidth, row * scaledTileHeight, 0, 0, scaledTileWidth, scaledTileHeight, 1, 1, 0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement