Coverage Summary for Class: TileMap (com.mygdx.game.Components)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| TileMap | 0% (0/1) | 0% (0/7) | 0% (0/16) |
1 package com.mygdx.game.Components; 2 3 import com.badlogic.gdx.maps.tiled.TiledMap; 4 import com.badlogic.gdx.maps.tiled.TiledMapRenderer; 5 import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; 6 import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; 7 import com.badlogic.gdx.math.Vector2; 8 import com.mygdx.game.Managers.RenderLayer; 9 import com.mygdx.game.Managers.RenderingManager; 10 import com.mygdx.game.Managers.ResourceManager; 11 12 import static com.mygdx.utils.Constants.TILE_SIZE; 13 14 /** 15 * Component that allows the rendering of tile-maps (has its own sprite batch) 16 */ 17 public class TileMap extends Component { 18 TiledMap map; 19 TiledMapRenderer renderer; 20 21 /** 22 * Sets up the base values of the TileMap component 23 */ 24 private TileMap() { 25 super(); 26 type = ComponentType.TileMap; 27 // CollisionManager.addTileMap(this); 28 } 29 30 /** 31 * @param id resource id of the tilemap 32 * @param layer rendering layer 33 */ 34 public TileMap(int id, RenderLayer layer) { 35 this(); 36 map = ResourceManager.getTileMap(id); 37 renderer = new OrthogonalTiledMapRenderer(map); 38 RenderingManager.addItem(this, layer); 39 40 TILE_SIZE = getTileDim().x; 41 } 42 43 /** 44 * @return the dimensions of the tilemap 45 */ 46 public Vector2 getTileDim() { 47 return new Vector2( 48 ((TiledMapTileLayer) map.getLayers().get(0)).getTileWidth(), 49 ((TiledMapTileLayer) map.getLayers().get(0)).getTileHeight()); 50 } 51 52 /** 53 * @return the map attached to this object 54 */ 55 public TiledMap getTileMap() { 56 return map; 57 } 58 59 /** 60 * Updates the renderer's view with the rendering camera 61 */ 62 @Override 63 public void update() { 64 super.update(); 65 renderer.setView(RenderingManager.getCamera()); 66 } 67 68 /** 69 * draws the first 2 layers 70 */ 71 @Override 72 public void render() { 73 super.render(); 74 renderer.render(new int[]{0, 1}); 75 } 76 77 /** 78 * Calls the Clean-Up function of the Component class 79 */ 80 @Override 81 public void cleanUp() { 82 super.cleanUp(); 83 } 84 85 //public TiledMapTileLayer.Cell getCell(Vector2 pos) { 86 // Vector2 p = pos.cpy(); 87 // TiledMapTileLayer l = (TiledMapTileLayer) map.getLayers().get(1); 88 // p.x /= l.getTileWidth(); 89 // p.y /= l.getTileHeight(); 90 // 91 // return l.getCell((int) p.x, (int) p.y); 92 // } 93 }