import static com.badlogic.gdx.graphics.g2d.SpriteBatch.*;
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.graphics.GL10;
-import com.badlogic.gdx.graphics.GL11;
-import com.badlogic.gdx.graphics.OrthographicCamera;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.graphics.g2d.SpriteCache;
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
-import com.badlogic.gdx.maps.MapLayer;
import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.MapRenderer;
-import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
-import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Polygon;
-import com.badlogic.gdx.math.Rectangle;
public interface TiledMapRenderer extends MapRenderer {
-
public void renderObject(MapObject object);
public void renderTileLayer(TiledMapTileLayer layer);
-
- public abstract class BatchTiledMapRenderer implements TiledMapRenderer {
-
- protected TiledMap map;
-
- protected float unitScale;
-
- protected SpriteBatch spriteBatch;
-
- protected Rectangle viewBounds;
-
- public TiledMap getMap() {
- return map;
- }
-
- public float getUnitScale() {
- return unitScale;
- }
-
- public SpriteBatch getSpriteBatch() {
- return spriteBatch;
- }
-
- public Rectangle getViewBounds() {
- return viewBounds;
- }
-
- public BatchTiledMapRenderer(TiledMap map) {
- this.map = map;
- this.unitScale = 1;
- this.spriteBatch = new SpriteBatch();
- this.viewBounds = new Rectangle();
- }
-
- public BatchTiledMapRenderer(TiledMap map, float unitScale) {
- this.map = map;
- this.unitScale = unitScale;
- this.viewBounds = new Rectangle();
- this.spriteBatch = new SpriteBatch();
- }
-
- @Override
- public void setView(OrthographicCamera camera) {
- spriteBatch.setProjectionMatrix(camera.combined);
- float width = camera.viewportWidth * camera.zoom;
- float height = camera.viewportHeight * camera.zoom;
- viewBounds.set(camera.position.x - width / 2, camera.position.y - height / 2, width, height);
- }
-
- @Override
- public void setView (Matrix4 projection, float x, float y, float width, float height) {
- spriteBatch.setProjectionMatrix(projection);
- viewBounds.set(x, y, width, height);
- }
-
- @Override
- public void render () {
- spriteBatch.begin();
- for (MapLayer layer : map.getLayers()) {
- if (layer.getVisible()) {
- if (layer instanceof TiledMapTileLayer) {
- renderTileLayer((TiledMapTileLayer) layer);
- } else {
- for (MapObject object : layer.getObjects()) {
- renderObject(object);
- }
- }
- }
- }
- spriteBatch.end();
- }
-
- @Override
- public void render (int[] layers) {
- spriteBatch.begin();
- for (int layerIdx : layers) {
- MapLayer layer = map.getLayers().getLayer(layerIdx);
- if (layer.getVisible()) {
- if (layer instanceof TiledMapTileLayer) {
- renderTileLayer((TiledMapTileLayer) layer);
- } else {
- for (MapObject object : layer.getObjects()) {
- renderObject(object);
- }
- }
- }
- }
- spriteBatch.end();
- }
- }
-
- public class IsometricTiledMapRenderer extends BatchTiledMapRenderer {
-
- private TiledMap map;
-
- private float[] vertices = new float[20];
-
- public IsometricTiledMapRenderer(TiledMap map) {
- super(map);
- }
-
- public IsometricTiledMapRenderer(TiledMap map, float unitScale) {
- super(map, unitScale);
- }
-
- @Override
- public void renderObject (MapObject object) {
-
- }
-
- @Override
- public void renderTileLayer (TiledMapTileLayer layer) {
-
- final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());
-
- int col1 = 0;
- int col2 = layer.getWidth() - 1;
-
- int row1 = 0;
- int row2 = layer.getHeight() - 1;
-
- float tileWidth = layer.getTileWidth() * unitScale;
- float tileHeight = layer.getTileHeight() * unitScale;
- float halfTileWidth = tileWidth * 0.5f;
- float halfTileHeight = tileHeight * 0.5f;
-
- for (int row = row2; row >= row1; row--) {
- for (int col = col1; col <= col2; col++) {
- float x = (col * halfTileWidth) + (row * halfTileWidth);
- float y = (row * halfTileHeight) - (col * halfTileHeight);
-
- final TiledMapTileLayer.Cell cell = layer.getCell(col, row);
- final TiledMapTile tile = cell.getTile();
- if (tile != null) {
-
- final boolean flipX = cell.getFlipHorizontally();
- final boolean flipY = cell.getFlipVertically();
- final int rotations = cell.getRotation();
-
- TextureRegion region = tile.getTextureRegion();
-
- float x1 = x;
- float y1 = y;
- float x2 = x1 + region.getRegionWidth() * unitScale;
- float y2 = y1 + region.getRegionHeight() * unitScale;
-
- float u1 = region.getU();
- float v1 = region.getV2();
- float u2 = region.getU2();
- float v2 = region.getV();
-
- vertices[X1] = x1;
- vertices[Y1] = y1;
- vertices[C1] = color;
- vertices[U1] = u1;
- vertices[V1] = v1;
-
- vertices[X2] = x1;
- vertices[Y2] = y2;
- vertices[C2] = color;
- vertices[U2] = u1;
- vertices[V2] = v2;
-
- vertices[X3] = x2;
- vertices[Y3] = y2;
- vertices[C3] = color;
- vertices[U3] = u2;
- vertices[V3] = v2;
-
- vertices[X4] = x2;
- vertices[Y4] = y1;
- vertices[C4] = color;
- vertices[U4] = u2;
- vertices[V4] = v1;
-
- if (flipX) {
- float temp = vertices[U1];
- vertices[U1] = vertices[U3];
- vertices[U3] = temp;
- temp = vertices[U2];
- vertices[U2] = vertices[U4];
- vertices[U4] = temp;
- }
- if (flipY) {
- float temp = vertices[V1];
- vertices[V1] = vertices[V3];
- vertices[V3] = temp;
- temp = vertices[V2];
- vertices[V2] = vertices[V4];
- vertices[V4] = temp;
- }
- if (rotations != 0) {
- switch (rotations) {
- case Cell.ROTATE_90: {
- float tempV = vertices[V1];
- vertices[V1] = vertices[V2];
- vertices[V2] = vertices[V3];
- vertices[V3] = vertices[V4];
- vertices[V4] = tempV;
-
- float tempU = vertices[U1];
- vertices[U1] = vertices[U2];
- vertices[U2] = vertices[U3];
- vertices[U3] = vertices[U4];
- vertices[U4] = tempU;
- break;
- }
- case Cell.ROTATE_180: {
- float tempU = vertices[U1];
- vertices[U1] = vertices[U3];
- vertices[U3] = tempU;
- tempU = vertices[U2];
- vertices[U2] = vertices[U4];
- vertices[U4] = tempU;
- float tempV = vertices[V1];
- vertices[V1] = vertices[V3];
- vertices[V3] = tempV;
- tempV = vertices[V2];
- vertices[V2] = vertices[V4];
- vertices[V4] = tempV;
- break;
- }
- case Cell.ROTATE_270: {
- float tempV = vertices[V1];
- vertices[V1] = vertices[V4];
- vertices[V4] = vertices[V3];
- vertices[V3] = vertices[V2];
- vertices[V2] = tempV;
-
- float tempU = vertices[U1];
- vertices[U1] = vertices[U4];
- vertices[U4] = vertices[U3];
- vertices[U3] = vertices[U2];
- vertices[U2] = tempU;
- break;
- }
- }
- }
- spriteBatch.draw(region.getTexture(), vertices, 0, 20);
- }
- }
- }
- }
-
- }
-
- public class OrthogonalTiledMapRenderer extends BatchTiledMapRenderer {
-
- private float[] vertices = new float[20];
-
- public OrthogonalTiledMapRenderer(TiledMap map) {
- super(map);
- }
-
- public OrthogonalTiledMapRenderer(TiledMap map, float unitScale) {
- super(map, unitScale);
- }
-
- @Override
- public void renderObject (MapObject object) {
-
- }
-
- @Override
- public void renderTileLayer (TiledMapTileLayer layer) {
-
- final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());
-
- final int layerWidth = layer.getWidth();
- final int layerHeight = layer.getHeight();
-
- final float layerTileWidth = layer.getTileWidth() * unitScale;
- final float layerTileHeight = layer.getTileHeight() * unitScale;
-
- final int col1 = Math.max(0, (int) (viewBounds.x / layerTileWidth));
- final int col2 = Math.min(layerWidth, (int) ((viewBounds.x + viewBounds.width + layerTileWidth) / layerTileWidth));
-
- final int row1 = Math.max(0, (int) (viewBounds.y / layerTileHeight));
- final int row2 = Math.min(layerHeight, (int) ((viewBounds.y + viewBounds.height + layerTileHeight) / layerTileHeight));
-
- for (int row = row1; row < row2; row++) {
- for (int col = col1; col < col2; col++) {
- final TiledMapTileLayer.Cell cell = layer.getCell(col, row);
- final TiledMapTile tile = cell.getTile();
- if (tile != null) {
-
- final boolean flipX = cell.getFlipHorizontally();
- final boolean flipY = cell.getFlipVertically();
- final int rotations = cell.getRotation();
-
- TextureRegion region = tile.getTextureRegion();
-
- float x1 = col * layerTileWidth;
- float y1 = row * layerTileHeight;
- float x2 = x1 + region.getRegionWidth() * unitScale;
- float y2 = y1 + region.getRegionHeight() * unitScale;
-
- float u1 = region.getU();
- float v1 = region.getV2();
- float u2 = region.getU2();
- float v2 = region.getV();
-
- vertices[X1] = x1;
- vertices[Y1] = y1;
- vertices[C1] = color;
- vertices[U1] = u1;
- vertices[V1] = v1;
-
- vertices[X2] = x1;
- vertices[Y2] = y2;
- vertices[C2] = color;
- vertices[U2] = u1;
- vertices[V2] = v2;
-
- vertices[X3] = x2;
- vertices[Y3] = y2;
- vertices[C3] = color;
- vertices[U3] = u2;
- vertices[V3] = v2;
-
- vertices[X4] = x2;
- vertices[Y4] = y1;
- vertices[C4] = color;
- vertices[U4] = u2;
- vertices[V4] = v1;
-
- if (flipX) {
- float temp = vertices[U1];
- vertices[U1] = vertices[U3];
- vertices[U3] = temp;
- temp = vertices[U2];
- vertices[U2] = vertices[U4];
- vertices[U4] = temp;
- }
- if (flipY) {
- float temp = vertices[V1];
- vertices[V1] = vertices[V3];
- vertices[V3] = temp;
- temp = vertices[V2];
- vertices[V2] = vertices[V4];
- vertices[V4] = temp;
- }
- if (rotations != 0) {
- switch (rotations) {
- case Cell.ROTATE_90: {
- float tempV = vertices[V1];
- vertices[V1] = vertices[V2];
- vertices[V2] = vertices[V3];
- vertices[V3] = vertices[V4];
- vertices[V4] = tempV;
-
- float tempU = vertices[U1];
- vertices[U1] = vertices[U2];
- vertices[U2] = vertices[U3];
- vertices[U3] = vertices[U4];
- vertices[U4] = tempU;
- break;
- }
- case Cell.ROTATE_180: {
- float tempU = vertices[U1];
- vertices[U1] = vertices[U3];
- vertices[U3] = tempU;
- tempU = vertices[U2];
- vertices[U2] = vertices[U4];
- vertices[U4] = tempU;
- float tempV = vertices[V1];
- vertices[V1] = vertices[V3];
- vertices[V3] = tempV;
- tempV = vertices[V2];
- vertices[V2] = vertices[V4];
- vertices[V4] = tempV;
- break;
- }
- case Cell.ROTATE_270: {
- float tempV = vertices[V1];
- vertices[V1] = vertices[V4];
- vertices[V4] = vertices[V3];
- vertices[V3] = vertices[V2];
- vertices[V2] = tempV;
-
- float tempU = vertices[U1];
- vertices[U1] = vertices[U4];
- vertices[U4] = vertices[U3];
- vertices[U3] = vertices[U2];
- vertices[U2] = tempU;
- break;
- }
- }
- }
- spriteBatch.draw(region.getTexture(), vertices, 0, 20);
- }
- }
- }
- }
-
- }
-
- public class OrthogonalTiledMapRenderer2 implements TiledMapRenderer {
-
- protected TiledMap map;
-
- protected float unitScale;
-
- protected SpriteCache spriteCache;
-
- protected Rectangle viewBounds;
-
- private float[] vertices = new float[20];
-
- public boolean recache;
-
- public OrthogonalTiledMapRenderer2(TiledMap map) {
- this.map = map;
- this.unitScale = 1;
- this.spriteCache = new SpriteCache(4000, true);
- this.viewBounds = new Rectangle();
- }
-
- public OrthogonalTiledMapRenderer2(TiledMap map, float unitScale) {
- this.map = map;
- this.unitScale = unitScale;
- this.viewBounds = new Rectangle();
- this.spriteCache = new SpriteCache(4000, true);
- }
-
- @Override
- public void setView(OrthographicCamera camera) {
- spriteCache.setProjectionMatrix(camera.combined);
- float width = camera.viewportWidth * camera.zoom;
- float height = camera.viewportHeight * camera.zoom;
- viewBounds.set(camera.position.x - width / 2, camera.position.y - height / 2, width, height);
- recache = true;
- }
-
- @Override
- public void setView (Matrix4 projection, float x, float y, float width, float height) {
- spriteCache.setProjectionMatrix(projection);
- viewBounds.set(x, y, width, height);
- recache = true;
- }
-
- public void begin () {
- if (recache) {
- cached = false;
- recache = false;
- spriteCache.clear();
- }
- if (!cached) {
- spriteCache.beginCache();
- } else {
- Gdx.gl.glEnable(GL10.GL_BLEND);
- Gdx.gl.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- spriteCache.begin();
- }
-
- }
-
- public void end () {
- if (!cached) {
- spriteCache.endCache();
- cached = true;
- begin();
- render();
- end();
- } else {
- spriteCache.end();
- Gdx.gl.glDisable(GL10.GL_BLEND);
- }
- }
-
- @Override
- public void render () {
- begin();
- if (cached) {
- spriteCache.draw(0);
- } else {
- for (MapLayer layer : map.getLayers()) {
- if (layer.getVisible()) {
- if (layer instanceof TiledMapTileLayer) {
- renderTileLayer((TiledMapTileLayer) layer);
- } else {
- for (MapObject object : layer.getObjects()) {
- renderObject(object);
- }
- }
- }
- }
- }
- end();
- }
-
- @Override
- public void render (int[] layers) {
- // FIXME not implemented
- throw new UnsupportedOperationException("Not implemented");
- }
-
- @Override
- public void renderObject (MapObject object) {
- // TODO Auto-generated method stub
-
- }
-
- boolean cached = false;
- int count = 0;
- @Override
- public void renderTileLayer (TiledMapTileLayer layer) {
- final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());
-
- final int layerWidth = layer.getWidth();
- final int layerHeight = layer.getHeight();
-
- final float layerTileWidth = layer.getTileWidth() * unitScale;
- final float layerTileHeight = layer.getTileHeight() * unitScale;
-
- final int col1 = Math.max(0, (int) (viewBounds.x / layerTileWidth));
- final int col2 = Math.min(layerWidth, (int) ((viewBounds.x + viewBounds.width + layerTileWidth) / layerTileWidth));
-
- final int row1 = Math.max(0, (int) (viewBounds.y / layerTileHeight));
- final int row2 = Math.min(layerHeight, (int) ((viewBounds.y + viewBounds.height + layerTileHeight) / layerTileHeight));
-
- for (int row = row1; row < row2; row++) {
- for (int col = col1; col < col2; col++) {
- final TiledMapTileLayer.Cell cell = layer.getCell(col, row);
- final TiledMapTile tile = cell.getTile();
- if (tile != null) {
- count++;
- final boolean flipX = cell.getFlipHorizontally();
- final boolean flipY = cell.getFlipVertically();
- final int rotations = cell.getRotation();
-
- TextureRegion region = tile.getTextureRegion();
-
- float x1 = col * layerTileWidth;
- float y1 = row * layerTileHeight;
- float x2 = x1 + region.getRegionWidth() * unitScale;
- float y2 = y1 + region.getRegionHeight() * unitScale;
-
- float u1 = region.getU();
- float v1 = region.getV2();
- float u2 = region.getU2();
- float v2 = region.getV();
-
- vertices[X1] = x1;
- vertices[Y1] = y1;
- vertices[C1] = color;
- vertices[U1] = u1;
- vertices[V1] = v1;
-
- vertices[X2] = x1;
- vertices[Y2] = y2;
- vertices[C2] = color;
- vertices[U2] = u1;
- vertices[V2] = v2;
-
- vertices[X3] = x2;
- vertices[Y3] = y2;
- vertices[C3] = color;
- vertices[U3] = u2;
- vertices[V3] = v2;
-
- vertices[X4] = x2;
- vertices[Y4] = y1;
- vertices[C4] = color;
- vertices[U4] = u2;
- vertices[V4] = v1;
-
- if (flipX) {
- float temp = vertices[U1];
- vertices[U1] = vertices[U3];
- vertices[U3] = temp;
- temp = vertices[U2];
- vertices[U2] = vertices[U4];
- vertices[U4] = temp;
- }
- if (flipY) {
- float temp = vertices[V1];
- vertices[V1] = vertices[V3];
- vertices[V3] = temp;
- temp = vertices[V2];
- vertices[V2] = vertices[V4];
- vertices[V4] = temp;
- }
- if (rotations != 0) {
- switch (rotations) {
- case Cell.ROTATE_90: {
- float tempV = vertices[V1];
- vertices[V1] = vertices[V2];
- vertices[V2] = vertices[V3];
- vertices[V3] = vertices[V4];
- vertices[V4] = tempV;
-
- float tempU = vertices[U1];
- vertices[U1] = vertices[U2];
- vertices[U2] = vertices[U3];
- vertices[U3] = vertices[U4];
- vertices[U4] = tempU;
- break;
- }
- case Cell.ROTATE_180: {
- float tempU = vertices[U1];
- vertices[U1] = vertices[U3];
- vertices[U3] = tempU;
- tempU = vertices[U2];
- vertices[U2] = vertices[U4];
- vertices[U4] = tempU;
- float tempV = vertices[V1];
- vertices[V1] = vertices[V3];
- vertices[V3] = tempV;
- tempV = vertices[V2];
- vertices[V2] = vertices[V4];
- vertices[V4] = tempV;
- break;
- }
- case Cell.ROTATE_270: {
- float tempV = vertices[V1];
- vertices[V1] = vertices[V4];
- vertices[V4] = vertices[V3];
- vertices[V3] = vertices[V2];
- vertices[V2] = tempV;
-
- float tempU = vertices[U1];
- vertices[U1] = vertices[U4];
- vertices[U4] = vertices[U3];
- vertices[U3] = vertices[U2];
- vertices[U2] = tempU;
- break;
- }
- }
- }
- spriteCache.add(region.getTexture(), vertices, 0, 20);
- }
- }
- }
- }
-
- }
}
--- /dev/null
+package com.badlogic.gdx.maps.tiled.renderers;\r
+\r
+import com.badlogic.gdx.graphics.OrthographicCamera;\r
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
+import com.badlogic.gdx.maps.MapLayer;\r
+import com.badlogic.gdx.maps.MapObject;\r
+import com.badlogic.gdx.maps.tiled.TiledMap;\r
+import com.badlogic.gdx.maps.tiled.TiledMapRenderer;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;\r
+import com.badlogic.gdx.math.Matrix4;\r
+import com.badlogic.gdx.math.Rectangle;\r
+\r
+public abstract class BatchTiledMapRenderer implements TiledMapRenderer {\r
+ \r
+ protected TiledMap map;\r
+\r
+ protected float unitScale;\r
+ \r
+ protected SpriteBatch spriteBatch;\r
+ \r
+ protected Rectangle viewBounds; \r
+\r
+ public TiledMap getMap() {\r
+ return map; \r
+ }\r
+ \r
+ public float getUnitScale() {\r
+ return unitScale;\r
+ }\r
+ \r
+ public SpriteBatch getSpriteBatch() {\r
+ return spriteBatch;\r
+ }\r
+\r
+ public Rectangle getViewBounds() {\r
+ return viewBounds;\r
+ }\r
+ \r
+ public BatchTiledMapRenderer(TiledMap map) {\r
+ this.map = map;\r
+ this.unitScale = 1;\r
+ this.spriteBatch = new SpriteBatch();\r
+ this.viewBounds = new Rectangle();\r
+ }\r
+ \r
+ public BatchTiledMapRenderer(TiledMap map, float unitScale) {\r
+ this.map = map;\r
+ this.unitScale = unitScale;\r
+ this.viewBounds = new Rectangle();\r
+ this.spriteBatch = new SpriteBatch();\r
+ }\r
+ \r
+ @Override\r
+ public void setView(OrthographicCamera camera) {\r
+ spriteBatch.setProjectionMatrix(camera.combined);\r
+ float width = camera.viewportWidth * camera.zoom;\r
+ float height = camera.viewportHeight * camera.zoom;\r
+ viewBounds.set(camera.position.x - width / 2, camera.position.y - height / 2, width, height);\r
+ }\r
+ \r
+ @Override\r
+ public void setView (Matrix4 projection, float x, float y, float width, float height) {\r
+ spriteBatch.setProjectionMatrix(projection);\r
+ viewBounds.set(x, y, width, height);\r
+ }\r
+ \r
+ @Override\r
+ public void render () {\r
+ spriteBatch.begin();\r
+ for (MapLayer layer : map.getLayers()) {\r
+ if (layer.getVisible()) {\r
+ if (layer instanceof TiledMapTileLayer) {\r
+ renderTileLayer((TiledMapTileLayer) layer);\r
+ } else {\r
+ for (MapObject object : layer.getObjects()) {\r
+ renderObject(object);\r
+ }\r
+ } \r
+ } \r
+ }\r
+ spriteBatch.end();\r
+ }\r
+ \r
+ @Override\r
+ public void render (int[] layers) {\r
+ spriteBatch.begin();\r
+ for (int layerIdx : layers) {\r
+ MapLayer layer = map.getLayers().getLayer(layerIdx);\r
+ if (layer.getVisible()) {\r
+ if (layer instanceof TiledMapTileLayer) {\r
+ renderTileLayer((TiledMapTileLayer) layer);\r
+ } else {\r
+ for (MapObject object : layer.getObjects()) {\r
+ renderObject(object);\r
+ }\r
+ } \r
+ } \r
+ } \r
+ spriteBatch.end();\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package com.badlogic.gdx.maps.tiled.renderers;\r
+\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y4;\r
+\r
+import com.badlogic.gdx.graphics.Color;\r
+import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
+import com.badlogic.gdx.maps.MapObject;\r
+import com.badlogic.gdx.maps.tiled.TiledMap;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTile;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;\r
+\r
+public class IsometricTiledMapRenderer extends BatchTiledMapRenderer {\r
+\r
+ private TiledMap map;\r
+ \r
+ private float[] vertices = new float[20];\r
+ \r
+ public IsometricTiledMapRenderer(TiledMap map) {\r
+ super(map);\r
+ }\r
+ \r
+ public IsometricTiledMapRenderer(TiledMap map, float unitScale) {\r
+ super(map, unitScale);\r
+ } \r
+ \r
+ @Override\r
+ public void renderObject (MapObject object) {\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public void renderTileLayer (TiledMapTileLayer layer) {\r
+\r
+ final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());\r
+ \r
+ int col1 = 0;\r
+ int col2 = layer.getWidth() - 1;\r
+ \r
+ int row1 = 0;\r
+ int row2 = layer.getHeight() - 1;\r
+ \r
+ float tileWidth = layer.getTileWidth() * unitScale;\r
+ float tileHeight = layer.getTileHeight() * unitScale;\r
+ float halfTileWidth = tileWidth * 0.5f;\r
+ float halfTileHeight = tileHeight * 0.5f;\r
+ \r
+ for (int row = row2; row >= row1; row--) {\r
+ for (int col = col1; col <= col2; col++) {\r
+ float x = (col * halfTileWidth) + (row * halfTileWidth);\r
+ float y = (row * halfTileHeight) - (col * halfTileHeight);\r
+\r
+ final TiledMapTileLayer.Cell cell = layer.getCell(col, row);\r
+ final TiledMapTile tile = cell.getTile();\r
+ if (tile != null) {\r
+ \r
+ final boolean flipX = cell.getFlipHorizontally();\r
+ final boolean flipY = cell.getFlipVertically();\r
+ final int rotations = cell.getRotation();\r
+ \r
+ TextureRegion region = tile.getTextureRegion();\r
+ \r
+ float x1 = x;\r
+ float y1 = y;\r
+ float x2 = x1 + region.getRegionWidth() * unitScale;\r
+ float y2 = y1 + region.getRegionHeight() * unitScale;\r
+ \r
+ float u1 = region.getU();\r
+ float v1 = region.getV2();\r
+ float u2 = region.getU2();\r
+ float v2 = region.getV();\r
+ \r
+ vertices[X1] = x1;\r
+ vertices[Y1] = y1;\r
+ vertices[C1] = color;\r
+ vertices[U1] = u1;\r
+ vertices[V1] = v1;\r
+ \r
+ vertices[X2] = x1;\r
+ vertices[Y2] = y2;\r
+ vertices[C2] = color;\r
+ vertices[U2] = u1;\r
+ vertices[V2] = v2;\r
+ \r
+ vertices[X3] = x2;\r
+ vertices[Y3] = y2;\r
+ vertices[C3] = color;\r
+ vertices[U3] = u2;\r
+ vertices[V3] = v2;\r
+ \r
+ vertices[X4] = x2;\r
+ vertices[Y4] = y1;\r
+ vertices[C4] = color;\r
+ vertices[U4] = u2;\r
+ vertices[V4] = v1; \r
+ \r
+ if (flipX) {\r
+ float temp = vertices[U1];\r
+ vertices[U1] = vertices[U3];\r
+ vertices[U3] = temp;\r
+ temp = vertices[U2];\r
+ vertices[U2] = vertices[U4];\r
+ vertices[U4] = temp;\r
+ }\r
+ if (flipY) {\r
+ float temp = vertices[V1];\r
+ vertices[V1] = vertices[V3];\r
+ vertices[V3] = temp;\r
+ temp = vertices[V2];\r
+ vertices[V2] = vertices[V4];\r
+ vertices[V4] = temp;\r
+ }\r
+ if (rotations != 0) {\r
+ switch (rotations) {\r
+ case Cell.ROTATE_90: {\r
+ float tempV = vertices[V1];\r
+ vertices[V1] = vertices[V2];\r
+ vertices[V2] = vertices[V3];\r
+ vertices[V3] = vertices[V4];\r
+ vertices[V4] = tempV;\r
+\r
+ float tempU = vertices[U1];\r
+ vertices[U1] = vertices[U2];\r
+ vertices[U2] = vertices[U3];\r
+ vertices[U3] = vertices[U4];\r
+ vertices[U4] = tempU; \r
+ break;\r
+ }\r
+ case Cell.ROTATE_180: {\r
+ float tempU = vertices[U1];\r
+ vertices[U1] = vertices[U3];\r
+ vertices[U3] = tempU;\r
+ tempU = vertices[U2];\r
+ vertices[U2] = vertices[U4];\r
+ vertices[U4] = tempU; \r
+ float tempV = vertices[V1];\r
+ vertices[V1] = vertices[V3];\r
+ vertices[V3] = tempV;\r
+ tempV = vertices[V2];\r
+ vertices[V2] = vertices[V4];\r
+ vertices[V4] = tempV;\r
+ break;\r
+ }\r
+ case Cell.ROTATE_270: {\r
+ float tempV = vertices[V1];\r
+ vertices[V1] = vertices[V4];\r
+ vertices[V4] = vertices[V3];\r
+ vertices[V3] = vertices[V2];\r
+ vertices[V2] = tempV;\r
+\r
+ float tempU = vertices[U1];\r
+ vertices[U1] = vertices[U4];\r
+ vertices[U4] = vertices[U3];\r
+ vertices[U3] = vertices[U2];\r
+ vertices[U2] = tempU; \r
+ break;\r
+ }\r
+ } \r
+ }\r
+ spriteBatch.draw(region.getTexture(), vertices, 0, 20);\r
+ } \r
+ }\r
+ }\r
+ }\r
+ \r
+}
\ No newline at end of file
--- /dev/null
+package com.badlogic.gdx.maps.tiled.renderers;\r
+\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y4;\r
+\r
+import com.badlogic.gdx.graphics.Color;\r
+import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
+import com.badlogic.gdx.maps.MapObject;\r
+import com.badlogic.gdx.maps.tiled.TiledMap;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTile;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;\r
+\r
+public class OrthogonalTiledMapRenderer extends BatchTiledMapRenderer {\r
+ \r
+ private float[] vertices = new float[20];\r
+ \r
+ public OrthogonalTiledMapRenderer(TiledMap map) {\r
+ super(map);\r
+ }\r
+\r
+ public OrthogonalTiledMapRenderer(TiledMap map, float unitScale) {\r
+ super(map, unitScale);\r
+ } \r
+ \r
+ @Override\r
+ public void renderObject (MapObject object) {\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void renderTileLayer (TiledMapTileLayer layer) {\r
+ \r
+ final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());\r
+ \r
+ final int layerWidth = layer.getWidth();\r
+ final int layerHeight = layer.getHeight();\r
+ \r
+ final float layerTileWidth = layer.getTileWidth() * unitScale;\r
+ final float layerTileHeight = layer.getTileHeight() * unitScale;\r
+ \r
+ final int col1 = Math.max(0, (int) (viewBounds.x / layerTileWidth));\r
+ final int col2 = Math.min(layerWidth, (int) ((viewBounds.x + viewBounds.width + layerTileWidth) / layerTileWidth));\r
+\r
+ final int row1 = Math.max(0, (int) (viewBounds.y / layerTileHeight));\r
+ final int row2 = Math.min(layerHeight, (int) ((viewBounds.y + viewBounds.height + layerTileHeight) / layerTileHeight)); \r
+ \r
+ for (int row = row1; row < row2; row++) {\r
+ for (int col = col1; col < col2; col++) {\r
+ final TiledMapTileLayer.Cell cell = layer.getCell(col, row);\r
+ final TiledMapTile tile = cell.getTile();\r
+ if (tile != null) {\r
+ \r
+ final boolean flipX = cell.getFlipHorizontally();\r
+ final boolean flipY = cell.getFlipVertically();\r
+ final int rotations = cell.getRotation();\r
+ \r
+ TextureRegion region = tile.getTextureRegion();\r
+ \r
+ float x1 = col * layerTileWidth;\r
+ float y1 = row * layerTileHeight;\r
+ float x2 = x1 + region.getRegionWidth() * unitScale;\r
+ float y2 = y1 + region.getRegionHeight() * unitScale;\r
+ \r
+ float u1 = region.getU();\r
+ float v1 = region.getV2();\r
+ float u2 = region.getU2();\r
+ float v2 = region.getV();\r
+ \r
+ vertices[X1] = x1;\r
+ vertices[Y1] = y1;\r
+ vertices[C1] = color;\r
+ vertices[U1] = u1;\r
+ vertices[V1] = v1;\r
+ \r
+ vertices[X2] = x1;\r
+ vertices[Y2] = y2;\r
+ vertices[C2] = color;\r
+ vertices[U2] = u1;\r
+ vertices[V2] = v2;\r
+ \r
+ vertices[X3] = x2;\r
+ vertices[Y3] = y2;\r
+ vertices[C3] = color;\r
+ vertices[U3] = u2;\r
+ vertices[V3] = v2;\r
+ \r
+ vertices[X4] = x2;\r
+ vertices[Y4] = y1;\r
+ vertices[C4] = color;\r
+ vertices[U4] = u2;\r
+ vertices[V4] = v1; \r
+ \r
+ if (flipX) {\r
+ float temp = vertices[U1];\r
+ vertices[U1] = vertices[U3];\r
+ vertices[U3] = temp;\r
+ temp = vertices[U2];\r
+ vertices[U2] = vertices[U4];\r
+ vertices[U4] = temp;\r
+ }\r
+ if (flipY) {\r
+ float temp = vertices[V1];\r
+ vertices[V1] = vertices[V3];\r
+ vertices[V3] = temp;\r
+ temp = vertices[V2];\r
+ vertices[V2] = vertices[V4];\r
+ vertices[V4] = temp;\r
+ }\r
+ if (rotations != 0) {\r
+ switch (rotations) {\r
+ case Cell.ROTATE_90: {\r
+ float tempV = vertices[V1];\r
+ vertices[V1] = vertices[V2];\r
+ vertices[V2] = vertices[V3];\r
+ vertices[V3] = vertices[V4];\r
+ vertices[V4] = tempV;\r
+\r
+ float tempU = vertices[U1];\r
+ vertices[U1] = vertices[U2];\r
+ vertices[U2] = vertices[U3];\r
+ vertices[U3] = vertices[U4];\r
+ vertices[U4] = tempU; \r
+ break;\r
+ }\r
+ case Cell.ROTATE_180: {\r
+ float tempU = vertices[U1];\r
+ vertices[U1] = vertices[U3];\r
+ vertices[U3] = tempU;\r
+ tempU = vertices[U2];\r
+ vertices[U2] = vertices[U4];\r
+ vertices[U4] = tempU; \r
+ float tempV = vertices[V1];\r
+ vertices[V1] = vertices[V3];\r
+ vertices[V3] = tempV;\r
+ tempV = vertices[V2];\r
+ vertices[V2] = vertices[V4];\r
+ vertices[V4] = tempV;\r
+ break;\r
+ }\r
+ case Cell.ROTATE_270: {\r
+ float tempV = vertices[V1];\r
+ vertices[V1] = vertices[V4];\r
+ vertices[V4] = vertices[V3];\r
+ vertices[V3] = vertices[V2];\r
+ vertices[V2] = tempV;\r
+\r
+ float tempU = vertices[U1];\r
+ vertices[U1] = vertices[U4];\r
+ vertices[U4] = vertices[U3];\r
+ vertices[U3] = vertices[U2];\r
+ vertices[U2] = tempU; \r
+ break;\r
+ }\r
+ } \r
+ }\r
+ spriteBatch.draw(region.getTexture(), vertices, 0, 20);\r
+ }\r
+ }\r
+ } \r
+ }\r
+ \r
+}
\ No newline at end of file
--- /dev/null
+package com.badlogic.gdx.maps.tiled.renderers;\r
+\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X4;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y1;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y2;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y3;\r
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y4;\r
+\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.graphics.Color;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.GL11;\r
+import com.badlogic.gdx.graphics.OrthographicCamera;\r
+import com.badlogic.gdx.graphics.g2d.SpriteCache;\r
+import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
+import com.badlogic.gdx.maps.MapLayer;\r
+import com.badlogic.gdx.maps.MapObject;\r
+import com.badlogic.gdx.maps.tiled.TiledMap;\r
+import com.badlogic.gdx.maps.tiled.TiledMapRenderer;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTile;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;\r
+import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;\r
+import com.badlogic.gdx.math.Matrix4;\r
+import com.badlogic.gdx.math.Rectangle;\r
+\r
+public class OrthogonalTiledMapRenderer2 implements TiledMapRenderer {\r
+\r
+ protected TiledMap map;\r
+\r
+ protected float unitScale;\r
+ \r
+ protected SpriteCache spriteCache;\r
+ \r
+ protected Rectangle viewBounds; \r
+ \r
+ private float[] vertices = new float[20];\r
+ \r
+ public boolean recache;\r
+ \r
+ public OrthogonalTiledMapRenderer2(TiledMap map) {\r
+ this.map = map;\r
+ this.unitScale = 1;\r
+ this.spriteCache = new SpriteCache(4000, true);\r
+ this.viewBounds = new Rectangle();\r
+ }\r
+ \r
+ public OrthogonalTiledMapRenderer2(TiledMap map, float unitScale) {\r
+ this.map = map;\r
+ this.unitScale = unitScale;\r
+ this.viewBounds = new Rectangle();\r
+ this.spriteCache = new SpriteCache(4000, true);\r
+ }\r
+ \r
+ @Override\r
+ public void setView(OrthographicCamera camera) {\r
+ spriteCache.setProjectionMatrix(camera.combined);\r
+ float width = camera.viewportWidth * camera.zoom;\r
+ float height = camera.viewportHeight * camera.zoom;\r
+ viewBounds.set(camera.position.x - width / 2, camera.position.y - height / 2, width, height);\r
+ recache = true;\r
+ }\r
+ \r
+ @Override\r
+ public void setView (Matrix4 projection, float x, float y, float width, float height) {\r
+ spriteCache.setProjectionMatrix(projection);\r
+ viewBounds.set(x, y, width, height);\r
+ recache = true;\r
+ }\r
+\r
+ public void begin () {\r
+ if (recache) {\r
+ cached = false;\r
+ recache = false;\r
+ spriteCache.clear();\r
+ }\r
+ if (!cached) {\r
+ spriteCache.beginCache(); \r
+ } else {\r
+ Gdx.gl.glEnable(GL10.GL_BLEND);\r
+ Gdx.gl.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);\r
+ spriteCache.begin();\r
+ }\r
+ \r
+ }\r
+\r
+ public void end () {\r
+ if (!cached) {\r
+ spriteCache.endCache();\r
+ cached = true;\r
+ begin();\r
+ render();\r
+ end();\r
+ } else {\r
+ spriteCache.end();\r
+ Gdx.gl.glDisable(GL10.GL_BLEND);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void render () {\r
+ begin();\r
+ if (cached) {\r
+ spriteCache.draw(0);\r
+ } else {\r
+ for (MapLayer layer : map.getLayers()) {\r
+ if (layer.getVisible()) {\r
+ if (layer instanceof TiledMapTileLayer) {\r
+ renderTileLayer((TiledMapTileLayer) layer);\r
+ } else {\r
+ for (MapObject object : layer.getObjects()) {\r
+ renderObject(object);\r
+ }\r
+ } \r
+ } \r
+ } \r
+ }\r
+ end();\r
+ }\r
+ \r
+ @Override\r
+ public void render (int[] layers) {\r
+ // FIXME not implemented\r
+ throw new UnsupportedOperationException("Not implemented");\r
+ }\r
+\r
+ @Override\r
+ public void renderObject (MapObject object) {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ boolean cached = false;\r
+ int count = 0;\r
+ @Override\r
+ public void renderTileLayer (TiledMapTileLayer layer) {\r
+ final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());\r
+ \r
+ final int layerWidth = layer.getWidth();\r
+ final int layerHeight = layer.getHeight();\r
+ \r
+ final float layerTileWidth = layer.getTileWidth() * unitScale;\r
+ final float layerTileHeight = layer.getTileHeight() * unitScale;\r
+ \r
+ final int col1 = Math.max(0, (int) (viewBounds.x / layerTileWidth));\r
+ final int col2 = Math.min(layerWidth, (int) ((viewBounds.x + viewBounds.width + layerTileWidth) / layerTileWidth));\r
+\r
+ final int row1 = Math.max(0, (int) (viewBounds.y / layerTileHeight));\r
+ final int row2 = Math.min(layerHeight, (int) ((viewBounds.y + viewBounds.height + layerTileHeight) / layerTileHeight)); \r
+ \r
+ for (int row = row1; row < row2; row++) {\r
+ for (int col = col1; col < col2; col++) {\r
+ final TiledMapTileLayer.Cell cell = layer.getCell(col, row);\r
+ final TiledMapTile tile = cell.getTile();\r
+ if (tile != null) {\r
+ count++;\r
+ final boolean flipX = cell.getFlipHorizontally();\r
+ final boolean flipY = cell.getFlipVertically();\r
+ final int rotations = cell.getRotation();\r
+ \r
+ TextureRegion region = tile.getTextureRegion();\r
+ \r
+ float x1 = col * layerTileWidth;\r
+ float y1 = row * layerTileHeight;\r
+ float x2 = x1 + region.getRegionWidth() * unitScale;\r
+ float y2 = y1 + region.getRegionHeight() * unitScale;\r
+ \r
+ float u1 = region.getU();\r
+ float v1 = region.getV2();\r
+ float u2 = region.getU2();\r
+ float v2 = region.getV();\r
+ \r
+ vertices[X1] = x1;\r
+ vertices[Y1] = y1;\r
+ vertices[C1] = color;\r
+ vertices[U1] = u1;\r
+ vertices[V1] = v1;\r
+ \r
+ vertices[X2] = x1;\r
+ vertices[Y2] = y2;\r
+ vertices[C2] = color;\r
+ vertices[U2] = u1;\r
+ vertices[V2] = v2;\r
+ \r
+ vertices[X3] = x2;\r
+ vertices[Y3] = y2;\r
+ vertices[C3] = color;\r
+ vertices[U3] = u2;\r
+ vertices[V3] = v2;\r
+ \r
+ vertices[X4] = x2;\r
+ vertices[Y4] = y1;\r
+ vertices[C4] = color;\r
+ vertices[U4] = u2;\r
+ vertices[V4] = v1; \r
+ \r
+ if (flipX) {\r
+ float temp = vertices[U1];\r
+ vertices[U1] = vertices[U3];\r
+ vertices[U3] = temp;\r
+ temp = vertices[U2];\r
+ vertices[U2] = vertices[U4];\r
+ vertices[U4] = temp;\r
+ }\r
+ if (flipY) {\r
+ float temp = vertices[V1];\r
+ vertices[V1] = vertices[V3];\r
+ vertices[V3] = temp;\r
+ temp = vertices[V2];\r
+ vertices[V2] = vertices[V4];\r
+ vertices[V4] = temp;\r
+ }\r
+ if (rotations != 0) {\r
+ switch (rotations) {\r
+ case Cell.ROTATE_90: {\r
+ float tempV = vertices[V1];\r
+ vertices[V1] = vertices[V2];\r
+ vertices[V2] = vertices[V3];\r
+ vertices[V3] = vertices[V4];\r
+ vertices[V4] = tempV;\r
+\r
+ float tempU = vertices[U1];\r
+ vertices[U1] = vertices[U2];\r
+ vertices[U2] = vertices[U3];\r
+ vertices[U3] = vertices[U4];\r
+ vertices[U4] = tempU; \r
+ break;\r
+ }\r
+ case Cell.ROTATE_180: {\r
+ float tempU = vertices[U1];\r
+ vertices[U1] = vertices[U3];\r
+ vertices[U3] = tempU;\r
+ tempU = vertices[U2];\r
+ vertices[U2] = vertices[U4];\r
+ vertices[U4] = tempU; \r
+ float tempV = vertices[V1];\r
+ vertices[V1] = vertices[V3];\r
+ vertices[V3] = tempV;\r
+ tempV = vertices[V2];\r
+ vertices[V2] = vertices[V4];\r
+ vertices[V4] = tempV;\r
+ break;\r
+ }\r
+ case Cell.ROTATE_270: {\r
+ float tempV = vertices[V1];\r
+ vertices[V1] = vertices[V4];\r
+ vertices[V4] = vertices[V3];\r
+ vertices[V3] = vertices[V2];\r
+ vertices[V2] = tempV;\r
+\r
+ float tempU = vertices[U1];\r
+ vertices[U1] = vertices[U4];\r
+ vertices[U4] = vertices[U3];\r
+ vertices[U3] = vertices[U2];\r
+ vertices[U2] = tempU; \r
+ break;\r
+ }\r
+ } \r
+ }\r
+ spriteCache.add(region.getTexture(), vertices, 0, 20);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+}
\ No newline at end of file
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
-import com.badlogic.gdx.maps.tiled.TiledMapRenderer.IsometricTiledMapRenderer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
+import com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer;
import com.badlogic.gdx.tests.utils.GdxTest;
import com.badlogic.gdx.tests.utils.OrthoCamController;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
import com.badlogic.gdx.maps.tiled.TiledMap;\r
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;\r
-import com.badlogic.gdx.maps.tiled.TiledMapRenderer.OrthogonalTiledMapRenderer;\r
import com.badlogic.gdx.maps.tiled.TmxMapLoader;\r
+import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;\r
import com.badlogic.gdx.tests.utils.GdxTest;\r
import com.badlogic.gdx.tests.utils.OrthoCamController;\r
\r
import com.badlogic.gdx.maps.MapLayers;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
-import com.badlogic.gdx.maps.tiled.TiledMapRenderer.OrthogonalTiledMapRenderer;
-import com.badlogic.gdx.maps.tiled.TiledMapRenderer.OrthogonalTiledMapRenderer2;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
+import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.tests.utils.GdxTest;