+/*******************************************************************************\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 com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;\r
\r
public class OrthogonalTiledMapRenderer extends BatchTiledMapRenderer {\r
- \r
private float[] vertices = new float[20];\r
- \r
+\r
public OrthogonalTiledMapRenderer(TiledMap map) {\r
super(map);\r
}\r
public OrthogonalTiledMapRenderer(TiledMap map, SpriteBatch spriteBatch) {\r
super(map, spriteBatch);\r
}\r
- \r
+\r
public OrthogonalTiledMapRenderer(TiledMap map, float unitScale) {\r
super(map, unitScale);\r
- } \r
- \r
+ }\r
+\r
public OrthogonalTiledMapRenderer(TiledMap map, float unitScale, SpriteBatch spriteBatch) {\r
super(map, unitScale, spriteBatch);\r
}\r
- \r
+\r
@Override\r
public void renderObject (MapObject object) {\r
\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
final int layerWidth = layer.getWidth();\r
final int layerHeight = layer.getHeight();\r
- \r
+\r
final float layerTileWidth = layer.getTileWidth() * unitScale;\r
final float layerTileHeight = layer.getTileHeight() * unitScale;\r
- \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
+\r
float y = row1 * layerTileHeight;\r
float xStart = col1 * layerTileWidth;\r
final float[] vertices = this.vertices;\r
- \r
+\r
for (int row = row1; row < row2; row++) {\r
float x = xStart;\r
for (int col = col1; col < col2; col++) {\r
continue;\r
}\r
final TiledMapTile tile = cell.getTile();\r
+\r
if (tile != null) {\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
x += layerTileWidth;\r
}\r
}\r
y += layerTileHeight;\r
- } \r
+ }\r
}\r
- \r
-}
\ No newline at end of file
+}\r