OSDN Git Service

[fixed] TileMapRenderer was culling incorrectly
authordfraska <dfraska@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sat, 30 Apr 2011 15:31:54 +0000 (15:31 +0000)
committerdfraska <dfraska@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sat, 30 Apr 2011 15:31:54 +0000 (15:31 +0000)
gdx/src/com/badlogic/gdx/graphics/g2d/tiled/TileMapRenderer.java
tests/gdx-tests/src/com/badlogic/gdx/tests/TiledMapTest.java

index 87daf4d..7f70ba1 100644 (file)
@@ -21,6 +21,7 @@ import com.badlogic.gdx.graphics.GL11;
 import com.badlogic.gdx.graphics.g2d.SpriteCache;\r
 import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;\r
 import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
+import com.badlogic.gdx.math.MathUtils;\r
 import com.badlogic.gdx.math.Matrix4;\r
 import com.badlogic.gdx.math.Vector2;\r
 import com.badlogic.gdx.utils.Disposable;\r
@@ -181,11 +182,11 @@ public class TileMapRenderer implements Disposable {
                normalCacheId = new int[map.length][][];\r
                blendedCacheId = new int[map.length][][];\r
                for (layer = 0; layer < map.length; layer++) {\r
-                       normalCacheId[layer] = new int[(int)Math.ceil((float)map[layer].length / tilesPerBlockY)][];\r
-                       blendedCacheId[layer] = new int[(int)Math.ceil((float)map[layer].length / tilesPerBlockY)][];\r
+                       normalCacheId[layer] = new int[(int)MathUtils.ceil((float)map[layer].length / tilesPerBlockY)][];\r
+                       blendedCacheId[layer] = new int[(int)MathUtils.ceil((float)map[layer].length / tilesPerBlockY)][];\r
                        for (row = 0; row < normalCacheId[layer].length; row++) {\r
-                               normalCacheId[layer][row] = new int[(int)Math.ceil(map[layer][row].length / tilesPerBlockX)];\r
-                               blendedCacheId[layer][row] = new int[(int)Math.ceil(map[layer][row].length / tilesPerBlockX)];\r
+                               normalCacheId[layer][row] = new int[(int)MathUtils.ceil((float)map[layer][row].length / tilesPerBlockX)];\r
+                               blendedCacheId[layer][row] = new int[(int)MathUtils.ceil((float)map[layer][row].length / tilesPerBlockX)];\r
                                for (col = 0; col < normalCacheId[layer][row].length; col++) {\r
                                        normalCacheId[layer][row][col] = addBlock(map[layer], layer, row, col, false);\r
                                        blendedCacheId[layer][row][col] = addBlock(map[layer], layer, row, col, true);\r
@@ -267,13 +268,14 @@ public class TileMapRenderer implements Disposable {
         *           number is too high.\r
         */\r
        public void render (float x, float y, int width, int height, int[] layers) {\r
-               initialRow = (int)((mapHeightPixels - y - overdrawY) / (tilesPerBlockY * tileHeight));\r
+               lastRow = (int)((mapHeightPixels - (y - height + overdrawY)) / (tilesPerBlockY * tileHeight));\r
+               initialRow = (int)((mapHeightPixels - (y - overdrawY))/(tilesPerBlockY * tileHeight));\r
                initialRow = (initialRow > 0) ? initialRow : 0; // Clamp initial Row > 0\r
+               \r
                initialCol = (int)((x - overdrawX) / (tilesPerBlockX * tileWidth));\r
                initialCol = (initialCol > 0) ? initialCol : 0; // Clamp initial Col > 0\r
-               lastRow = (int)((mapHeightPixels - y + height + overdrawY) / (tilesPerBlockY * tileHeight)); // clamping done in render loop\r
-               lastCol = (int)((x + width + overdrawX) / (tilesPerBlockX * tileWidth)); // clamping done in render loop\r
-\r
+               lastCol = (int)((x + width + overdrawX) / (tilesPerBlockX * tileWidth));\r
+                               \r
                Gdx.gl.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);\r
 \r
                cache.begin();\r
index 8de68f8..f9052c5 100644 (file)
@@ -47,7 +47,7 @@ public class TiledMapTest extends GdxTest {
        private static final int SCREEN_WIDTH = 480;\r
        private static final int SCREEN_HEIGHT = 320;\r
 \r
-       private static final int[] layersList = {2,3};\r
+       //private static final int[] layersList = {2,3};\r
 \r
        SpriteBatch spriteBatch;\r
        BitmapFont font;\r
@@ -76,7 +76,7 @@ public class TiledMapTest extends GdxTest {
                tmp.set(0, 0, 0);\r
                cam.unproject(tmp);\r
 \r
-               tileMapRenderer.render(tmp.x, tmp.y, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), layersList);\r
+               tileMapRenderer.render(tmp.x, tmp.y, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());//, layersList);\r
 \r
                spriteBatch.begin();\r
                font.draw(spriteBatch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 20, 20);\r