OSDN Git Service

Add TideMapLoader
authorJustin Shapcott <support@mobidevelop.com>
Sun, 17 Feb 2013 20:28:40 +0000 (13:28 -0700)
committerJustin Shapcott <support@mobidevelop.com>
Sun, 17 Feb 2013 20:28:40 +0000 (13:28 -0700)
Modified other classes as necessary to support the Tide loader.

gdx/src/com/badlogic/gdx/maps/tiled/TideMapLoader.java [new file with mode: 0644]
gdx/src/com/badlogic/gdx/maps/tiled/TiledMap.java
gdx/src/com/badlogic/gdx/maps/tiled/TiledMapRenderer.java
gdx/src/com/badlogic/gdx/maps/tiled/TiledMapTileSet.java
gdx/src/com/badlogic/gdx/maps/tiled/tiles/AnimatedTiledMapTile.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/TiledMapAssetManagerTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/TiledMapDirectLoaderTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bench/TiledMapBench.java

diff --git a/gdx/src/com/badlogic/gdx/maps/tiled/TideMapLoader.java b/gdx/src/com/badlogic/gdx/maps/tiled/TideMapLoader.java
new file mode 100644 (file)
index 0000000..f9e0f04
--- /dev/null
@@ -0,0 +1,286 @@
+package com.badlogic.gdx.maps.tiled;
+
+import java.io.IOException;
+import java.util.StringTokenizer;
+
+import com.badlogic.gdx.assets.AssetDescriptor;
+import com.badlogic.gdx.assets.AssetLoaderParameters;
+import com.badlogic.gdx.assets.AssetManager;
+import com.badlogic.gdx.assets.loaders.FileHandleResolver;
+import com.badlogic.gdx.assets.loaders.SynchronousAssetLoader;
+import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
+import com.badlogic.gdx.files.FileHandle;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.maps.ImageResolver;
+import com.badlogic.gdx.maps.MapProperties;
+import com.badlogic.gdx.maps.ImageResolver.AssetManagerImageResolver;
+import com.badlogic.gdx.maps.ImageResolver.DirectImageResolver;
+import com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile;
+import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
+import com.badlogic.gdx.utils.Array;
+import com.badlogic.gdx.utils.GdxRuntimeException;
+import com.badlogic.gdx.utils.ObjectMap;
+import com.badlogic.gdx.utils.XmlReader;
+import com.badlogic.gdx.utils.XmlReader.Element;
+
+public class TideMapLoader extends SynchronousAssetLoader<TiledMap, TideMapLoader.Parameters> {
+
+       public static class Parameters extends AssetLoaderParameters<TiledMap> {
+               
+       }
+       
+       private XmlReader xml = new XmlReader();
+       private Element root;
+       
+       public TideMapLoader() {
+               super(new InternalFileHandleResolver());
+       }
+       
+       public TideMapLoader (FileHandleResolver resolver) {
+               super(resolver);
+       }
+
+       public TiledMap load (String fileName) {
+               try {
+                       FileHandle tideFile = resolve(fileName);
+                       root = xml.parse(tideFile);
+                       ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
+                       for(FileHandle textureFile: loadTileSheets(root, tideFile)) {
+                               textures.put(textureFile.path(), new Texture(textureFile));
+                       }
+                       DirectImageResolver imageResolver = new DirectImageResolver(textures);
+                       TiledMap map = loadMap(root, tideFile, imageResolver);
+                       map.setOwnedTextures(textures.values().toArray());
+                       return map;
+               } catch(IOException e) {
+                       throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
+               }
+
+       }
+       
+       @Override
+       public TiledMap load (AssetManager assetManager, String fileName, Parameters parameter) {
+               FileHandle tideFile = resolve(fileName);
+               try {
+                       return loadMap(root, tideFile, new AssetManagerImageResolver(assetManager));
+               } catch (Exception e) {
+                       throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
+               }
+       }
+
+       @Override
+       public Array<AssetDescriptor> getDependencies (String fileName, Parameters parameter) {
+               Array<AssetDescriptor> dependencies = new Array<AssetDescriptor>();
+               try {
+                       FileHandle tmxFile = resolve(fileName);
+                       root = xml.parse(tmxFile);
+                       for(FileHandle image: loadTileSheets(root, tmxFile)) {
+                               dependencies.add(new AssetDescriptor(image.path(), Texture.class));
+                       }
+                       return dependencies;
+               } catch (IOException e) {
+                       throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
+               }
+       }
+       
+       /**
+        * Loads the map data, given the XML root element and an {@link ImageResolver} used
+        * to return the tileset Textures
+        * @param root the XML root element 
+        * @param tmxFile the Filehandle of the tmx file
+        * @param imageResolver the {@link ImageResolver}
+        * @return the {@link TiledMap}
+        */
+       private TiledMap loadMap(Element root, FileHandle tmxFile, ImageResolver imageResolver) {
+               TiledMap map = new TiledMap();
+               Element properties = root.getChildByName("properties");
+               if (properties != null) {
+                       loadProperties(map.getProperties(), properties);
+               }
+               Element tilesheets = root.getChildByName("TileSheets");
+               for (Element tilesheet : tilesheets.getChildrenByName("TileSheet")) {
+                       loadTileSheet(map, tilesheet, tmxFile, imageResolver);
+               }
+               Element layers = root.getChildByName("Layers");
+               for (Element layer : layers.getChildrenByName("Layer")) {
+                       loadLayer(map, layer);
+               }
+               return map;
+       }
+       
+       /**
+        * Loads the tilesets
+        * @param root the root XML element
+        * @return a list of filenames for images containing tiles
+        * @throws IOException 
+        */
+       private Array<FileHandle> loadTileSheets(Element root, FileHandle tideFile) throws IOException {
+               Array<FileHandle> images = new Array<FileHandle>();
+               Element tilesheets = root.getChildByName("TileSheets");
+               for (Element tileset : tilesheets.getChildrenByName("TileSheet")) {
+                       Element imageSource = tileset.getChildByName("ImageSource");
+                       FileHandle image = getRelativeFileHandle(tideFile, imageSource.getText());
+                       images.add(image);
+               }
+               return images;
+       }
+       
+       private void loadTileSheet(TiledMap map, Element element, FileHandle tideFile, ImageResolver imageResolver) {
+               if (element.getName().equals("TileSheet")) {
+                       String id = element.getAttribute("Id");
+                       String description = element.getChildByName("Description").getText();
+                       String imageSource = element.getChildByName("ImageSource").getText();
+                       
+                       Element alignment = element.getChildByName("Alignment");
+                       String sheetSize = alignment.getAttribute("SheetSize");
+                       String tileSize = alignment.getAttribute("TileSize");
+                       String margin = alignment.getAttribute("Margin");
+                       String spacing = alignment.getAttribute("Spacing");
+                       
+                       String[] sheetSizeParts = sheetSize.split(" x ");
+                       int sheetSizeX = Integer.parseInt(sheetSizeParts[0]);
+                       int sheetSizeY = Integer.parseInt(sheetSizeParts[1]);
+                       
+                       String[] tileSizeParts = tileSize.split(" x ");
+                       int tileSizeX = Integer.parseInt(tileSizeParts[0]);
+                       int tileSizeY = Integer.parseInt(tileSizeParts[1]);
+                       
+                       String[] marginParts = margin.split(" x ");
+                       int marginX = Integer.parseInt(marginParts[0]);
+                       int marginY = Integer.parseInt(marginParts[1]);
+
+                       String[] spacingParts = margin.split(" x ");
+                       int spacingX = Integer.parseInt(spacingParts[0]);
+                       int spacingY = Integer.parseInt(spacingParts[1]);
+
+                       FileHandle image = getRelativeFileHandle(tideFile, imageSource);
+                       Texture texture = imageResolver.getImage(image.path());
+                       
+                       // TODO: Actually load the tilesheet
+                       // Need to make global ids as Tide doesn't have global ids.
+                       TiledMapTileSets tilesets = map.getTileSets();
+                       int firstgid = 1;
+                       for (TiledMapTileSet tileset : tilesets) {
+                               firstgid += tileset.size();
+                       }
+                       
+                       TiledMapTileSet tileset = new TiledMapTileSet();
+                       tileset.setName(id);
+                       tileset.getProperties().put("firstgid", firstgid);
+                       int gid = firstgid;
+                       
+                       int stopWidth = texture.getWidth() - tileSizeX;
+                       int stopHeight = texture.getHeight() - tileSizeY;
+                       
+                       for (int y = marginY; y <= stopHeight; y += tileSizeY + spacingY) {
+                               for (int x = marginX; x <= stopWidth; x += tileSizeX + spacingX) {
+                                       TiledMapTile tile = new StaticTiledMapTile(new TextureRegion(texture, x, y, tileSizeX, tileSizeY));
+                                       tileset.putTile(gid++, tile);
+                               }
+                       }
+                       
+                       Element properties = element.getChildByName("Proeprties");
+                       if (properties != null) {
+                               loadProperties(tileset.getProperties(), properties);
+                       }
+                       
+                       tilesets.addTileSet(tileset);
+               }
+       }
+       
+       private void loadLayer(TiledMap map, Element element) {
+               if (element.getName().equals("Layer")) {
+                       String id = element.getAttribute("Id");
+                       String visible = element.getAttribute("Visible");
+                       
+                       Element dimensions = element.getChildByName("Dimensions");
+                       String layerSize = dimensions.getAttribute("LayerSize");
+                       String tileSize = dimensions.getAttribute("TileSize");
+                       
+                       String[] layerSizeParts = layerSize.split(" x ");
+                       int layerSizeX = Integer.parseInt(layerSizeParts[0]);
+                       int layerSizeY = Integer.parseInt(layerSizeParts[1]);
+                       
+                       String[] tileSizeParts = tileSize.split(" x ");
+                       int tileSizeX = Integer.parseInt(tileSizeParts[0]);
+                       int tileSizeY = Integer.parseInt(tileSizeParts[1]);
+                       
+                       TiledMapTileLayer layer = new TiledMapTileLayer(layerSizeX, layerSizeY, tileSizeX, tileSizeY);
+                       Element tileArray = element.getChildByName("TileArray");
+                       Array<Element> rows = tileArray.getChildrenByName("Row");
+                       TiledMapTileSets tilesets = map.getTileSets();
+                       TiledMapTileSet currentTileSet = null;
+                       int firstgid = 0;
+                       int x, y;
+                       for (int row = 0, rowCount = rows.size; row < rowCount; row++) {
+                               Element currentRow = rows.get(row);
+                               y = row;
+                               x = 0;
+                               for (int child = 0, childCount = currentRow.getChildCount(); child < childCount; child++) {
+                                       Element currentChild = currentRow.getChild(child);
+                                       String name = currentChild.getName();
+                                       if (name.equals("TileSheet")) {
+                                               currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref"));
+                                               firstgid = currentTileSet.getProperties().getAsInteger("firstgid");
+                                       } else if (name.equals("Null")) {
+                                               x += currentChild.getIntAttribute("Count");
+                                       } else if (name.equals("Static")) {
+                                               layer.setCell(x, y, currentTileSet.getTile(firstgid + currentChild.getIntAttribute("Index")));
+                                       } else if (name.equals("Animated")) {
+                                               // Create an AnimatedTile
+                                               int interval = currentChild.getInt("Interval");
+                                               Element frames = currentChild.getChildByName("Frames");
+                                               Array<StaticTiledMapTile> frameTiles = new Array<StaticTiledMapTile>();
+                                               for (int frameChild = 0, frameChildCount = frames.getChildCount(); frameChild < frameChildCount; frameChild++) {
+                                                       Element frame = frames.getChild(frameChild);
+                                                       String frameName = frame.getName();
+                                                       if (frameName.equals("TileSheet")) {
+                                                               currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref"));
+                                                               firstgid = currentTileSet.getProperties().getAsInteger("firstgid");
+                                                       } else if (frameName.equals("Static")) {
+                                                               frameTiles.add((StaticTiledMapTile) currentTileSet.getTile(firstgid + frame.getIntAttribute("Index")));
+                                                       }
+                                               }
+                                               layer.setCell(x, y, new AnimatedTiledMapTile(interval / 1000f, frameTiles)); //TODO: Reuse existing animated tiles
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       private void loadProperties(MapProperties properties, Element element) {
+               if (element.getName().equals("Properties")) {
+                       for (Element property : element.getChildrenByName("Property")) {
+                               String key = property.getAttribute("Key", null);
+                               String type = property.getAttribute("Type", null);
+                               String value = property.getText();
+                               
+                               if (type.equals("Int32")) {
+                                       
+                               } else if (type.equals("String")) {
+                                       
+                               } else if (type.equals("Boolean")) {
+                                       
+                               } else {
+                                       properties.put(key, value);                                     
+                               }
+                       }
+               }
+       }
+       
+       private static FileHandle getRelativeFileHandle(FileHandle file, String path) {
+               StringTokenizer tokenizer = new StringTokenizer(path, "\\/");
+               FileHandle result = file.parent();
+               while (tokenizer.hasMoreElements()) {
+                       String token = tokenizer.nextToken();
+                       if (token.equals(".."))
+                               result = result.parent();
+                       else {
+                               result = result.child(token);
+                       }
+               }
+               return result;          
+       }
+
+}
index bd2aed1..e8a0552 100644 (file)
@@ -6,7 +6,7 @@ import com.badlogic.gdx.maps.Map;
 import com.badlogic.gdx.utils.Array;
 
 /**
- * @brief Represents a Tiled created map, adds the concept of tiles and tilesets
+ * @brief Represents a tiled map, adds the concept of tiles and tilesets
  * 
  * @see Map
  */
index e3e89da..6d865b4 100644 (file)
@@ -1,27 +1,44 @@
 package com.badlogic.gdx.maps.tiled;
 
-import static com.badlogic.gdx.graphics.g2d.SpriteBatch.*;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C1;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C2;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C3;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.C4;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U1;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U2;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U3;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.U4;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V1;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V2;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V3;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.V4;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X1;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X2;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X3;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.X4;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y1;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y2;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y3;
+import static com.badlogic.gdx.graphics.g2d.SpriteBatch.Y4;
 
 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.tiled.TiledMapTileLayer.Cell;
 import com.badlogic.gdx.math.Matrix4;
-import com.badlogic.gdx.math.Polygon;
 import com.badlogic.gdx.math.Rectangle;
 
 public interface TiledMapRenderer {
        
-       public void setViewBounds(float x, float y, float width, float height);
-       
-       public void setProjectionMatrix(Matrix4 projection);
+       public void setView(Matrix4 projectionMatrix, float viewBoundsX, float viewBoundsY, float viewBoundsWidth, float viewBoundsHeight);
+       public void setView(OrthographicCamera camera);
        
        public void begin();
        public void end();
@@ -71,13 +88,14 @@ public interface TiledMapRenderer {
                }
                
                @Override
-               public void setViewBounds (float x, float y, float width, float height) {
-                       viewBounds.set(x, y, width, height);
+               public void setView(Matrix4 projectionMatrix, float viewBoundsX, float viewBoundsY, float viewBoundsWidth, float viewBoundsHeight) {
+                       spriteBatch.setProjectionMatrix(projectionMatrix);
+                       viewBounds.set(viewBoundsX, viewBoundsY, viewBoundsWidth, viewBoundsHeight);
                }
                
                @Override
-               public void setProjectionMatrix (Matrix4 projection) {
-                       spriteBatch.setProjectionMatrix(projection);
+               public void setView(OrthographicCamera camera) {
+                       setView(camera.combined, camera.position.x - camera.viewportWidth / 2, camera.position.y - camera.viewportHeight / 2, camera.viewportWidth, camera.viewportHeight);
                }
                
                @Override
@@ -157,13 +175,14 @@ public interface TiledMapRenderer {
                }
                
                @Override
-               public void setViewBounds (float x, float y, float width, float height) {
-                       viewBounds.set(x, y, width, height);
+               public void setView(Matrix4 projectionMatrix, float viewBoundsX, float viewBoundsY, float viewBoundsWidth, float viewBoundsHeight) {
+                       spriteCache.setProjectionMatrix(projectionMatrix);
+                       viewBounds.set(viewBoundsX, viewBoundsY, viewBoundsWidth, viewBoundsHeight);
                }
                
                @Override
-               public void setProjectionMatrix (Matrix4 projection) {
-                       spriteCache.setProjectionMatrix(projection);
+               public void setView(OrthographicCamera camera) {
+                       setView(camera.combined, camera.position.x - camera.viewportWidth / 2, camera.position.y - camera.viewportHeight / 2, camera.viewportWidth, camera.viewportHeight);
                }
                
                @Override
@@ -508,7 +527,7 @@ public interface TiledMapRenderer {
                
        }
 
-       public class OrthogonalTiledMapRenderer2 implements TiledMapRenderer {
+       public class OrthogonalTiledMapRenderer2 extends CacheTiledMapRenderer {
 
                protected TiledMap map;
 
@@ -523,27 +542,11 @@ public interface TiledMapRenderer {
                public boolean recache;
                
                public OrthogonalTiledMapRenderer2(TiledMap map) {
-                       this.map = map;
-                       this.unitScale = 1;
-                       this.spriteCache = new SpriteCache(4000, true);
-                       this.viewBounds = new Rectangle();
+                       super(map);
                }
                
                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 setViewBounds (float x, float y, float width, float height) {
-                       viewBounds.set(x, y, width, height);
-               }
-
-               @Override
-               public void setProjectionMatrix (Matrix4 projection) {
-                       spriteCache.setProjectionMatrix(projection);
+                       super(map, unitScale);
                }
 
                @Override
@@ -597,12 +600,6 @@ public interface TiledMapRenderer {
 
                }
 
-               @Override
-               public void renderObject (MapObject object) {
-                       // TODO Auto-generated method stub
-                       
-               }
-
                boolean cached = false;
                int count = 0;
                @Override
index 3affe23..ed5ff81 100644 (file)
@@ -67,5 +67,10 @@ public class TiledMapTileSet {
        public void removeTile(int id) {
                tiles.remove(id);
        }
+
+       public int size() {
+               return tiles.size;
+       }
        
 }
+
diff --git a/gdx/src/com/badlogic/gdx/maps/tiled/tiles/AnimatedTiledMapTile.java b/gdx/src/com/badlogic/gdx/maps/tiled/tiles/AnimatedTiledMapTile.java
new file mode 100644 (file)
index 0000000..bc192f0
--- /dev/null
@@ -0,0 +1,47 @@
+package com.badlogic.gdx.maps.tiled.tiles;
+
+import com.badlogic.gdx.graphics.g2d.Animation;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.maps.MapProperties;
+import com.badlogic.gdx.maps.tiled.TiledMapTile;
+import com.badlogic.gdx.utils.Array;
+
+public class AnimatedTiledMapTile implements TiledMapTile {
+
+       private Array<StaticTiledMapTile> frameTiles;
+       
+       private float animationTime;
+       
+       @Override
+       public BlendMode getBlendMode () {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void setBlendMode (BlendMode blendMode) {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public TextureRegion getTextureRegion () {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public MapProperties getProperties () {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public AnimatedTiledMapTile(float interval, Array<StaticTiledMapTile> frameTiles) {
+
+       }
+       
+       public void setAnimationTime(float animationTime) {
+               this.animationTime = animationTime;
+       }
+       
+}
index d5af65f..38f6e2b 100644 (file)
@@ -53,8 +53,7 @@ public class TiledMapAssetManagerTest extends GdxTest {
                Gdx.gl.glClearColor(100f / 255f, 100f / 255f, 250f / 255f, 1f);
                Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
                camera.update();
-               renderer.setProjectionMatrix(camera.combined);
-               renderer.setViewBounds(camera.position.x - camera.viewportWidth * 0.5f, camera.position.y - camera.viewportHeight * 0.5f, camera.viewportWidth, camera.viewportHeight);
+               renderer.setView(camera);
                renderer.begin();
                renderer.render();
                renderer.end();
index 1a30ec3..27921c3 100755 (executable)
@@ -55,8 +55,7 @@ public class TiledMapDirectLoaderTest extends GdxTest {
                Gdx.gl.glClearColor(0.55f, 0.55f, 0.55f, 1f);\r
                Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
                camera.update();\r
-               renderer.setProjectionMatrix(camera.combined);\r
-               renderer.setViewBounds(camera.position.x - camera.viewportWidth * 0.5f, camera.position.y - camera.viewportHeight * 0.5f, camera.viewportWidth, camera.viewportHeight);\r
+               renderer.setView(camera);\r
                renderer.begin();\r
                renderer.render();\r
                renderer.end();\r
index 4079b1a..a9ca8cc 100644 (file)
@@ -78,11 +78,10 @@ public class TiledMapBench extends GdxTest {
                Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
                if (cameraController.dirty) {
                        camera.update();
-                       renderer.setProjectionMatrix(camera.combined);
+                       renderer.setView(camera);
                        cameraController.dirty = false;
                        ((OrthogonalTiledMapRenderer2) renderer).recache = true;
                }
-               renderer.setViewBounds(camera.position.x - camera.viewportWidth * 0.5f, camera.position.y - camera.viewportHeight * 0.5f, camera.viewportWidth, camera.viewportHeight);
                renderer.begin();
                renderer.render();
                renderer.end();