import com.badlogic.gdx.utils.XmlReader;
import com.badlogic.gdx.utils.XmlReader.Element;
+/**
+ * @brief synchronous loader for TMX maps created with the Tiled tool
+ */
public class TmxMapLoader extends SynchronousAssetLoader<TiledMap, TmxMapLoader.Parameters> {
public static class Parameters extends AssetLoaderParameters<TiledMap> {
private FileHandle tmx;
private XmlReader xml;
+ /**
+ * Creates loader
+ *
+ * @param resolver
+ */
public TmxMapLoader(FileHandleResolver resolver) {
super(resolver);
}
+ /**
+ * Loads a .tmx file
+ *
+ * @param assetManager
+ * @param fileName
+ * @param parameter not used for now
+ * @return loaded TiledMap instance
+ */
@Override
public TiledMap load(AssetManager assetManager, String fileName, Parameters parameter) {
this.assetManager = assetManager;
return null;
}
+ /**
+ * Retrieves TiledMap resource dependencies
+ *
+ * @param fileName
+ * @param parameter not used for now
+ * @return dependencies for the given .tmx file
+ */
@Override
public Array<AssetDescriptor> getDependencies(String fileName, Parameters parameter) {
Array<AssetDescriptor> dependencies = new Array<AssetDescriptor>();
import com.badlogic.gdx.maps.Map;
+/**
+ * @brief Represents a Tiled created map, adds the concept of tiles and tilesets
+ *
+ * @see Map
+ */
public class TiledMap extends Map {
private TiledMapTileSets tilesets;
+ /**
+ * @return collection of tilesets for this map
+ */
public TiledMapTileSets getTileSets() {
return tilesets;
}
+ /**
+ * Creates empty TiledMap
+ */
public TiledMap() {
tilesets = new TiledMapTileSets();
}
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.Disposable;
+/**
+ * @brief Logic for rendering TiledMap objects
+ *
+ * Includes several optimisations such as SpriteCache usage, fustrum culling etc.
+ */
public class TiledMapRenderer implements MapRenderer, Disposable {
private Map map;
private boolean ownsSpriteBatch = false;
+ /**
+ * @return map currently being used for rendering
+ */
public Map getMap() {
return map;
}
+ /**
+ * @return batch used for rendering
+ */
public SpriteBatch getSpriteBatch() {
return spriteBatch;
}
+ /**
+ * @return world units per pixel used for rendering
+ */
public float getUnitScale() {
return unitScale;
}
+ /**
+ * Creates a renderer from a map. Will use own spritebatch and world units of 1.0 pixels
+ *
+ * @param map will use this map for rendering
+ */
public TiledMapRenderer(TiledMap map) {
this(map, new SpriteBatch());
ownsSpriteBatch = true;
}
+ /**
+ * Creates a renderer from a map using the given world units. Will use a batch from its own.
+ *
+ * @param map will use this map for rendering
+ * @param unitScale world units per pixel
+ */
public TiledMapRenderer(TiledMap map, float unitScale) {
this(map, new SpriteBatch(), unitScale);
ownsSpriteBatch = true;
}
+ /**
+ * @param map will use this map for rendering
+ * @param spriteBatch batch that will be used for rendering
+ */
public TiledMapRenderer(TiledMap map, SpriteBatch spriteBatch) {
this.map = map;
this.spriteBatch = spriteBatch;
this.ownsSpriteBatch = false;
}
+ /**
+ * @param map will use this map for rendering
+ * @param spriteBatch batch that will be used for rendering
+ * @param unitScale world units per pixel
+ */
public TiledMapRenderer(TiledMap map, SpriteBatch spriteBatch, float unitScale) {
this.map = map;
this.spriteBatch = spriteBatch;
this.ownsSpriteBatch = false;
}
+ /**
+ * @param projection projection matrix that will be used for rendering the map
+ */
@Override
public void setProjectionMatrix (Matrix4 projection) {
spriteBatch.setProjectionMatrix(projection);
}
}
- /* (non-Javadoc)
- * @see com.badlogic.gdx.maps.MapRenderer2#render(float, float, float, float, int[])
+ /**
+ * Renders all the layers using the projection matrix and the given bounds for fustrum culling
+ *
+ * @param viewboundsX
+ * @param viewboundsY
+ * @param viewboundsWidth
+ * @param viewboundsHeight
*/
@Override
public void render (float viewboundsX, float viewboundsY, float viewboundsWidth, float viewboundsHeight) {
}
}
- /* (non-Javadoc)
- * @see com.badlogic.gdx.maps.MapRenderer2#render(float, float, float, float, int[])
+ /**
+ * Renders the given layers using the projection matrix and the given bounds for fustrum culling
+ *
+ * @param viewboundsX
+ * @param viewboundsY
+ * @param viewboundsWidth
+ * @param viewboundsHeight
+ * @param layers
*/
@Override
public void render (float viewboundsX, float viewboundsY, float viewboundsWidth, float viewboundsHeight, int[] layers) {
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.MapProperties;
+/**
+ * @brief Generalises the concept of tile in a TiledMap
+ *
+ */
public interface TiledMapTile {
+ /**
+ * @return texture region used to render the tile
+ */
public TextureRegion getTextureRegion();
+ /**
+ * @return tile's properties set
+ */
public MapProperties getProperties();
}
import com.badlogic.gdx.maps.MapLayer;
+/**
+ * @brief Layer for a TiledMap
+ */
public class TiledMapTileLayer extends MapLayer {
private int width;
private Cell[][] cells;
+ /**
+ * @return layer's witdth in tiles
+ */
public int getWidth() {
return width;
}
+ /**
+ * @return layer's height in tiles
+ */
public int getHeight() {
return height;
}
+ /**
+ * @return tiles' width in pixels
+ */
public float getTileWidth() {
return tileWidth;
}
+ /**
+ * @return tiles' height in pixels
+ */
public float getTileHeight() {
return tileHeight;
}
+ /**
+ * Creates TiledMap layer
+ *
+ * @param width layer width in tiles
+ * @param height layer height in tiles
+ * @param tileWidth tile width in pixels
+ * @param tileHeight tile height in pixels
+ */
public TiledMapTileLayer(int width, int height, int tileWidth, int tileHeight) {
super();
this.width = width;
}
}
+ /**
+ * @param x
+ * @param y
+ * @return cell at (x, y)
+ */
public Cell getCell(int x, int y) {
return cells[x][y];
}
cells[x][y].setTile(tile);
}
+ /**
+ * @brief represents a slot in a TiledLayer: TiledMapTile, flip and rotation properties.
+ */
public class Cell {
private TiledMapTile tile;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.utils.IntMap;
+/**
+ * @brief Set of TiledMapTile instances used to compose a TiledMapLayer
+ */
public class TiledMapTileSet {
private String name;
private MapProperties properties;
+ /**
+ * @return tileset's name
+ */
public String getName() {
return name;
}
+ /**
+ * @param name new name for the tileset
+ */
public void setName(String name) {
this.name = name;
}
+ /**
+ * @return tileset's properties set
+ */
public MapProperties getProperties() {
return properties;
}
+ /**
+ * Creates empty tileset
+ */
public TiledMapTileSet() {
tiles = new IntMap<TiledMapTile>();
properties = new MapProperties();
}
+ /**
+ * @param id
+ * @return tile matching id, null if it doesn't exist
+ */
public TiledMapTile getTile(int id) {
return tiles.get(id);
}
+ /**
+ * Adds or replaces tile with that id
+ *
+ * @param id
+ * @param tile
+ */
public void putTile(int id, TiledMapTile tile) {
tiles.put(id, tile);
}
+ /**
+ * @param id tile's id to be removed
+ */
public void removeTile(int id) {
tiles.remove(id);
}
import com.badlogic.gdx.utils.Array;
+/**
+ * @brief Collection of TiledMapTileSet
+ */
public class TiledMapTileSets implements Iterable<TiledMapTileSet> {
private Array<TiledMapTileSet> tilesets;
+ /**
+ * Creates empty collection of tilesets
+ */
public TiledMapTileSets() {
tilesets = new Array<TiledMapTileSet>();
}
+ /**
+ * @param index
+ * @return tileset at index
+ */
public TiledMapTileSet getTileSet(int index) {
return tilesets.get(index);
}
+ /**
+ * @param name
+ * @return tileset with matching name, null if it doesn't exist
+ */
public TiledMapTileSet getTileSet(String name) {
for (TiledMapTileSet tileset : tilesets) {
if (name.equals(tileset.getName())) {
return null;
}
+ /**
+ * @param tileset set to be added to the collection
+ */
public void addTileSet(TiledMapTileSet tileset) {
tilesets.add(tileset);
}
+ /**
+ * Removes tileset at index
+ *
+ * @param index
+ */
public void removeTileSet(int index) {
tilesets.removeIndex(index);
}
+ /**
+ * @param tileset set to be removed
+ */
public void removeTileSet(TiledMapTileSet tileset) {
tilesets.removeValue(tileset, true);
}
+ /**
+ * @param id
+ * @return tile with matching id, null if it doesn't exist
+ */
public TiledMapTile getTile(int id) {
for (TiledMapTileSet tileset : tilesets) {
TiledMapTile tile = tileset.getTile(id);
return null;
}
+ /**
+ * @return iterator to tilesets
+ */
@Override
public Iterator<TiledMapTileSet> iterator() {
return tilesets.iterator();
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.TiledMapTile;
+/**
+ * @brief Represents a non changing TiledMapTile (can be cached)
+ */
public class StaticTiledMapTile implements TiledMapTile {
private MapProperties properties;
private TextureRegion textureRegion;
+ /**
+ * @return tile's properties set
+ */
@Override
public MapProperties getProperties() {
return properties;
}
-
+
+ /**
+ * @return texture region used to render the tile
+ */
@Override
public TextureRegion getTextureRegion() {
return textureRegion;
}
+ /**
+ * Creates a static tile with the given region
+ *
+ * @param textureRegion
+ */
public StaticTiledMapTile(TextureRegion textureRegion) {
this.textureRegion = textureRegion;
}
+ /**
+ * Copy constructor
+ *
+ * @param copy
+ */
public StaticTiledMapTile(StaticTiledMapTile copy) {
this.properties.putAll(copy.properties);
this.textureRegion = copy.textureRegion;