libgdx API

com.badlogic.gdx.graphics.g2d.tiled
Class TileMapRenderer

java.lang.Object
  extended by com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer
All Implemented Interfaces:
Disposable

public class TileMapRenderer
extends java.lang.Object
implements Disposable

A renderer for Tiled maps backed with a Sprite Cache.

Author:
David Fraska

Field Summary
 float overdrawX
          Sets the amount of overdraw in the X direction (in units).
 float overdrawY
          Sets the amount of overdraw in the Y direction (in units).
 
Constructor Summary
TileMapRenderer(int[][][] map, TileAtlas atlas, int tileWidth, int tileHeight, float unitsPerTileX, float unitsPerTileY, IntArray blendedTiles, int tilesPerBlockX, int tilesPerBlockY)
          A renderer for static tile maps backed with a Sprite Cache.
TileMapRenderer(int[][][] map, TileAtlas atlas, int tileWidth, int tileHeight, float unitsPerTileX, float unitsPerTileY, IntArray blendedTiles, int tilesPerBlockX, int tilesPerBlockY, ShaderProgram shader)
          A renderer for static tile maps backed with a Sprite Cache.
TileMapRenderer(TiledMap map, TileAtlas atlas, int tilesPerBlockX, int tilesPerBlockY)
          A renderer for static tile maps backed with a Sprite Cache.
TileMapRenderer(TiledMap map, TileAtlas atlas, int tilesPerBlockX, int tilesPerBlockY, float unitsPerTileX, float unitsPerTileY)
          A renderer for static tile maps backed with a Sprite Cache.
TileMapRenderer(TiledMap map, TileAtlas atlas, int tilesPerBlockX, int tilesPerBlockY, float unitsPerTileX, float unitsPerTileY, ShaderProgram shader)
           
TileMapRenderer(TiledMap map, TileAtlas atlas, int tilesPerBlockX, int tilesPerBlockY, ShaderProgram shader)
          A renderer for static tile maps backed with a Sprite Cache.
 
Method Summary
 void dispose()
          Releases all resources held by this TiledMapRenderer.
 TileAtlas getAtlas()
           
 int getCol(int worldX)
          Computes the Tiled Map column given an X coordinate in units
 int getInitialCol()
          Returns the initial drawn block column, for debugging purposes.
 int getInitialRow()
          Returns the initial drawn block row, for debugging purposes.
 int getLastCol()
          Returns the final drawn block column, for debugging purposes.
 int getLastRow()
          Returns the final drawn block row, for debugging purposes.
 TiledMap getMap()
           
 int getMapHeightUnits()
           
 int getMapWidthUnits()
           
 Matrix4 getProjectionMatrix()
           
 int getRow(int worldY)
          Computes the Tiled Map row given a Y coordinate in units
 Matrix4 getTransformMatrix()
           
 float getUnitsPerTileX()
           
 float getUnitsPerTileY()
           
 void render()
          Renders the entire map.
 void render(float x, float y, float width, float height)
          Renders all layers between the given bounding box in map units.
 void render(float x, float y, float width, float height, int[] layers)
          Renders specific layers between the given bounding box in map units.
 void render(OrthographicCamera cam)
          Renders specific layers in the given a camera
 void render(OrthographicCamera cam, int[] layers)
          Renders specific layers in the given a camera.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

overdrawX

public float overdrawX
Sets the amount of overdraw in the X direction (in units). Use this if an actual tile width is greater than the tileWidth specified in the constructor. Use the value actual_tile_width - tileWidth (from the constructor).


overdrawY

public float overdrawY
Sets the amount of overdraw in the Y direction (in units). Use this if an actual tile height is greater than the tileHeight specified in the constructor. Use the value actual_tile_height - tileHeight (from the constructor).

Constructor Detail

TileMapRenderer

public TileMapRenderer(TiledMap map,
                       TileAtlas atlas,
                       int tilesPerBlockX,
                       int tilesPerBlockY)
A renderer for static tile maps backed with a Sprite Cache. This constructor is for convenience when loading TiledMaps. The normal Tiled coordinate system is used when placing tiles. A default shader is used if OpenGL ES 2.0 is enabled. The tilesPerBlockX and tilesPerBlockY parameters will need to be adjusted for best performance. Smaller values will cull more precisely, but result in longer loading times. Larger values result in shorter loading times, but will cull less precisely.

Parameters:
map - A tile map's tile numbers, in the order [layer][row][column]
atlas - The tile atlas to be used when drawing the map
tilesPerBlockX - The width of each block to be drawn, in number of tiles
tilesPerBlockY - The height of each block to be drawn, in number of tiles

TileMapRenderer

public TileMapRenderer(TiledMap map,
                       TileAtlas atlas,
                       int tilesPerBlockX,
                       int tilesPerBlockY,
                       float unitsPerTileX,
                       float unitsPerTileY)
A renderer for static tile maps backed with a Sprite Cache. This constructor is for convenience when loading TiledMaps. A default shader is used if OpenGL ES 2.0 is enabled. The tilesPerBlockX and tilesPerBlockY parameters will need to be adjusted for best performance. Smaller values will cull more precisely, but result in longer loading times. Larger values result in shorter loading times, but will cull less precisely.

Parameters:
map - A tile map's tile numbers, in the order [layer][row][column]
atlas - The tile atlas to be used when drawing the map
tilesPerBlockX - The width of each block to be drawn, in number of tiles
tilesPerBlockY - The height of each block to be drawn, in number of tiles
unitsPerTileX - The number of units per tile in the x direction
unitsPerTileY - The number of units per tile in the y direction

TileMapRenderer

public TileMapRenderer(TiledMap map,
                       TileAtlas atlas,
                       int tilesPerBlockX,
                       int tilesPerBlockY,
                       ShaderProgram shader)
A renderer for static tile maps backed with a Sprite Cache. This constructor is for convenience when loading TiledMaps. The normal Tiled coordinate system is used when placing tiles. The tilesPerBlockX and tilesPerBlockY parameters will need to be adjusted for best performance. Smaller values will cull more precisely, but result in longer loading times. Larger values result in shorter loading times, but will cull less precisely.

Parameters:
map - A tile map's tile numbers, in the order [layer][row][column]
atlas - The tile atlas to be used when drawing the map
tilesPerBlockX - The width of each block to be drawn, in number of tiles
tilesPerBlockY - The height of each block to be drawn, in number of tiles
shader - Shader to use for OpenGL ES 2.0, null uses a default shader. Ignored if using OpenGL ES 1.0.

TileMapRenderer

public TileMapRenderer(TiledMap map,
                       TileAtlas atlas,
                       int tilesPerBlockX,
                       int tilesPerBlockY,
                       float unitsPerTileX,
                       float unitsPerTileY,
                       ShaderProgram shader)

TileMapRenderer

public TileMapRenderer(int[][][] map,
                       TileAtlas atlas,
                       int tileWidth,
                       int tileHeight,
                       float unitsPerTileX,
                       float unitsPerTileY,
                       IntArray blendedTiles,
                       int tilesPerBlockX,
                       int tilesPerBlockY)
A renderer for static tile maps backed with a Sprite Cache. The tilesPerBlockX and tilesPerBlockY parameters will need to be adjusted for best performance. Smaller values will cull more precisely, but result in longer loading times. Larger values result in shorter loading times, but will cull less precisely. A default shader is used if OpenGL ES 2.0 is enabled.

Parameters:
map - A tile map's tile numbers, in the order [layer][row][column]
atlas - The tile atlas to be used when drawing the map
tileWidth - The width of the tiles, in pixels
tileHeight - The height of the tiles, in pixels
unitsPerTileX - The number of units per tile in the x direction
unitsPerTileY - The number of units per tile in the y direction
blendedTiles - Array containing tile numbers that require blending
tilesPerBlockX - The width of each block to be drawn, in number of tiles
tilesPerBlockY - The height of each block to be drawn, in number of tiles

TileMapRenderer

public TileMapRenderer(int[][][] map,
                       TileAtlas atlas,
                       int tileWidth,
                       int tileHeight,
                       float unitsPerTileX,
                       float unitsPerTileY,
                       IntArray blendedTiles,
                       int tilesPerBlockX,
                       int tilesPerBlockY,
                       ShaderProgram shader)
A renderer for static tile maps backed with a Sprite Cache. The tilesPerBlockX and tilesPerBlockY parameters will need to be adjusted for best performance. Smaller values will cull more precisely, but result in longer loading times. Larger values result in shorter loading times, but will cull less precisely.

Parameters:
map - A tile map's tile numbers, in the order [layer][row][column]
atlas - The tile atlas to be used when drawing the map
tileWidth - The width of the tiles, in pixels
tileHeight - The height of the tiles, in pixels
unitsPerTileX - The number of units per tile in the x direction
unitsPerTileY - The number of units per tile in the y direction
blendedTiles - Array containing tile numbers that require blending
tilesPerBlockX - The width of each block to be drawn, in number of tiles
tilesPerBlockY - The height of each block to be drawn, in number of tiles
shader - Shader to use for OpenGL ES 2.0, null uses a default shader. Ignored if using OpenGL ES 1.0.
Method Detail

render

public void render()
Renders the entire map. Use this function only on very small maps or for debugging purposes. The size of the map is based on the first layer and the first row's size.


render

public void render(float x,
                   float y,
                   float width,
                   float height)
Renders all layers between the given bounding box in map units. This is the same as calling render(float, float, float, float, int[]) with all layers in the layers list.


render

public void render(OrthographicCamera cam)
Renders specific layers in the given a camera

Parameters:
cam - The camera to use

render

public void render(OrthographicCamera cam,
                   int[] layers)
Renders specific layers in the given a camera.

Parameters:
cam - The camera to use
layers - The list of layers to draw, 0 being the lowest layer. You will get an IndexOutOfBoundsException if a layer number is too high.

render

public void render(float x,
                   float y,
                   float width,
                   float height,
                   int[] layers)
Renders specific layers between the given bounding box in map units.

Parameters:
x - The x coordinate to start drawing
y - the y coordinate to start drawing
width - the width of the tiles to draw
height - the width of the tiles to draw
layers - The list of layers to draw, 0 being the lowest layer. You will get an IndexOutOfBoundsException if a layer number is too high.

getProjectionMatrix

public Matrix4 getProjectionMatrix()

getTransformMatrix

public Matrix4 getTransformMatrix()

getRow

public int getRow(int worldY)
Computes the Tiled Map row given a Y coordinate in units

Parameters:
worldY - the Y coordinate in units

getCol

public int getCol(int worldX)
Computes the Tiled Map column given an X coordinate in units

Parameters:
worldX - the X coordinate in units

getInitialRow

public int getInitialRow()
Returns the initial drawn block row, for debugging purposes. Use this along with getLastRow() to compute the number of rows drawn in the last call to render(float, float, float, float, int[]).


getInitialCol

public int getInitialCol()
Returns the initial drawn block column, for debugging purposes. Use this along with getLastCol() to compute the number of columns drawn in the last call to render(float, float, float, float, int[]).


getLastRow

public int getLastRow()
Returns the final drawn block row, for debugging purposes. Use this along with getInitialRow() to compute the number of rows drawn in the last call to render(float, float, float, float, int[]).


getLastCol

public int getLastCol()
Returns the final drawn block column, for debugging purposes. Use this along with getInitialCol() to compute the number of columns drawn in the last call to render(float, float, float, float, int[]).


getUnitsPerTileX

public float getUnitsPerTileX()

getUnitsPerTileY

public float getUnitsPerTileY()

getMapHeightUnits

public int getMapHeightUnits()

getMapWidthUnits

public int getMapWidthUnits()

dispose

public void dispose()
Releases all resources held by this TiledMapRenderer.

Specified by:
dispose in interface Disposable

getMap

public TiledMap getMap()

getAtlas

public TileAtlas getAtlas()

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)