OSDN Git Service

[fixed] issue in TileMapRenderer where having unitsPerTileX/Y not matching the tileWi...
authorJustin Shapcott <justin@mobidevelop.com>
Sun, 23 Sep 2012 13:51:18 +0000 (06:51 -0700)
committerJustin Shapcott <justin@mobidevelop.com>
Sun, 23 Sep 2012 13:51:18 +0000 (06:51 -0700)
gdx/src/com/badlogic/gdx/graphics/g2d/tiled/TileMapRenderer.java

index 981d422..e665599 100644 (file)
@@ -20,11 +20,9 @@ import com.badlogic.gdx.graphics.GL10;
 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.TextureAtlas.AtlasRegion;\r
 import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
 import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
 import com.badlogic.gdx.math.MathUtils;\r
-import com.badlogic.gdx.math.Matrix3;\r
 import com.badlogic.gdx.math.Matrix4;\r
 import com.badlogic.gdx.math.Vector3;\r
 import com.badlogic.gdx.utils.Disposable;\r
@@ -254,6 +252,9 @@ public class TileMapRenderer implements Disposable {
                int lastCol = firstCol + tilesPerBlockX;\r
                int lastRow = firstRow + tilesPerBlockY;\r
 \r
+               float offsetX =  ((tileWidth - unitsPerTileX) / 2);\r
+               float offsetY =  ((tileHeight - unitsPerTileY) / 2);\r
+               \r
                for (int row = firstRow; row < lastRow && row < layer.length; row++) {\r
                        for (int col = firstCol; col < lastCol && col < layer[row].length; col++) {\r
                                int tile = layer[row][col];\r
@@ -269,8 +270,8 @@ public class TileMapRenderer implements Disposable {
                                                TextureRegion reg = atlas.getRegion(tile);\r
                                                if (reg != null) {\r
                                                        \r
-                                                       float x = col * unitsPerTileX;\r
-                                                       float y = (layer.length - row - 1) * unitsPerTileY;\r
+                                                       float x = col * unitsPerTileX - offsetX;\r
+                                                       float y = (layer.length - row - 1) * unitsPerTileY - offsetY;\r
                                                        float width = reg.getRegionWidth();\r
                                                        float height = reg.getRegionHeight();                                                   \r
                                                        float originX = width * 0.5f;\r