+/*******************************************************************************\r
+ * Copyright 2013 See AUTHORS file.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ ******************************************************************************/\r
+\r
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
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.*;\r
\r
import com.badlogic.gdx.graphics.Color;\r
import com.badlogic.gdx.graphics.g2d.SpriteBatch;\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
+public class IsometricTiledMapRenderer extends BatchTiledMapRenderer {\r
private float[] vertices = new float[20];\r
- \r
+\r
public IsometricTiledMapRenderer(TiledMap map) {\r
super(map);\r
}\r
public IsometricTiledMapRenderer(TiledMap map, SpriteBatch spriteBatch) {\r
super(map, spriteBatch);\r
}\r
- \r
+\r
public IsometricTiledMapRenderer(TiledMap map, float unitScale) {\r
super(map, unitScale);\r
- } \r
- \r
+ } \r
+\r
public IsometricTiledMapRenderer(TiledMap map, float unitScale, SpriteBatch spriteBatch) {\r
super(map, unitScale, spriteBatch);\r
}\r
- \r
+\r
@Override\r
public void renderObject (MapObject object) {\r
\r
}\r
- \r
+\r
@Override\r
public void renderTileLayer (TiledMapTileLayer layer) {\r
final Color batchColor = spriteBatch.getColor();\r
final float color = Color.toFloatBits(batchColor.r, batchColor.g, batchColor.b, batchColor.a * layer.getOpacity());\r
- \r
+ \r
int col1 = 0;\r
int col2 = layer.getWidth() - 1;\r
- \r
+\r
int row1 = 0;\r
int row2 = layer.getHeight() - 1;\r
- \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
+\r
for (int row = row2; row >= row1; row--) {\r
for (int col = col1; col <= col2; col++) {\r
float x = (col * halfTileWidth) + (row * halfTileWidth);\r
final TiledMapTileLayer.Cell cell = layer.getCell(col, row);\r
if(cell == null) continue;\r
final TiledMapTile tile = cell.getTile();\r
+\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
+\r
TextureRegion region = tile.getTextureRegion();\r
- \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
+\r
float u1 = region.getU();\r
float v1 = region.getV2();\r
float u2 = region.getU2();\r
float v2 = region.getV();\r
- \r
+\r
vertices[X1] = x1;\r
vertices[Y1] = y1;\r
vertices[C1] = color;\r
vertices[U1] = u1;\r
vertices[V1] = v1;\r
- \r
+\r
vertices[X2] = x1;\r
vertices[Y2] = y2;\r
vertices[C2] = color;\r
vertices[U2] = u1;\r
vertices[V2] = v2;\r
- \r
+\r
vertices[X3] = x2;\r
vertices[Y3] = y2;\r
vertices[C3] = color;\r
vertices[U3] = u2;\r
vertices[V3] = v2;\r
- \r
+\r
vertices[X4] = x2;\r
vertices[Y4] = y1;\r
vertices[C4] = color;\r
vertices[U4] = u2;\r
- vertices[V4] = v1; \r
- \r
+ vertices[V4] = v1;\r
+\r
if (flipX) {\r
float temp = vertices[U1];\r
vertices[U1] = vertices[U3];\r
vertices[U1] = vertices[U2];\r
vertices[U2] = vertices[U3];\r
vertices[U3] = vertices[U4];\r
- vertices[U4] = tempU; \r
+ vertices[U4] = tempU;\r
break;\r
}\r
case Cell.ROTATE_180: {\r
vertices[U3] = tempU;\r
tempU = vertices[U2];\r
vertices[U2] = vertices[U4];\r
- vertices[U4] = tempU; \r
+ vertices[U4] = tempU;\r
float tempV = vertices[V1];\r
vertices[V1] = vertices[V3];\r
vertices[V3] = tempV;\r
vertices[U1] = vertices[U4];\r
vertices[U4] = vertices[U3];\r
vertices[U3] = vertices[U2];\r
- vertices[U2] = tempU; \r
+ vertices[U2] = tempU;\r
break;\r
}\r
- } \r
+ }\r
}\r
spriteBatch.draw(region.getTexture(), vertices, 0, 20);\r
- } \r
+ }\r
}\r
}\r
}\r
- \r
-}
\ No newline at end of file
+}\r