libgdx API

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

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

public class TiledMapRenderer
extends java.lang.Object
implements Disposable

A renderer for Tiled maps backed with a Sprite Cache.

Author:
David Fraska

Constructor Summary
TiledMapRenderer(TiledMap map, TileAtlas atlas, int blockWidth, int blockHeight)
          A renderer for Tiled maps backed with a Sprite Cache.
TiledMapRenderer(TiledMap map, TileAtlas atlas, int blockWidth, int blockHeight, ShaderProgram shader)
          A renderer for Tiled maps backed with a Sprite Cache.
 
Method Summary
 void dispose()
          Releases all resources held by this TiledMapRenderer.
 int getCol(int worldX)
          Computes the Tiled Map column given an X coordinate in pixels
 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.
 int getMapHeightPixels()
           
 int getMapWidthPixels()
           
 Matrix4 getProjectionMatrix()
           
 int getRow(int worldY)
          Computes the Tiled Map row given a Y coordinate in pixels
 Matrix4 getTransformMatrix()
           
 void render()
          Renders the entire map.
 void render(int x, int y, int width, int height)
          Renders all layers between the given Tiled world coordinates.
 void render(int x, int y, int width, int height, int[] layers)
          Renders specific layers between the given Tiled world coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TiledMapRenderer

public TiledMapRenderer(TiledMap map,
                        TileAtlas atlas,
                        int blockWidth,
                        int blockHeight)
A renderer for Tiled maps backed with a Sprite Cache. The blockWidth and blockHeight parameters are used to determine how many tiles are in each block. When render(int, int, int, int, int[]) is called, each block will equate one call to SpriteCache.draw(int). For debugging, use getInitialCol(), getInitialRow(), getLastCol(), and getLastRow() after calling render(int, int, int, int, int[]) to determine how many blocks were drawn.

Parameters:
map - A Tiled map that has been run through the TiledMapPacker, which will add a few properties to optimize the renderer
atlas - The tile atlas to be used when drawing the map
blockWidth - The width of each block to be drawn, in pixels
blockHeight - The width of each block to be drawn, in pixels

TiledMapRenderer

public TiledMapRenderer(TiledMap map,
                        TileAtlas atlas,
                        int blockWidth,
                        int blockHeight,
                        ShaderProgram shader)
A renderer for Tiled maps backed with a Sprite Cache. The blockWidth and blockHeight parameters are used to determine how many tiles are in each block. When render(int, int, int, int, int[]) is called, each block will equate one call to SpriteCache.draw(int). For debugging, use getInitialCol(), getInitialRow(), getLastCol(), and getLastRow() after calling render(int, int, int, int, int[]) to determine how many blocks were drawn.

Parameters:
map - The map to be drawn
atlas - The tile atlas to be used when drawing the map
blockWidth - The width of each block to be drawn, in pixels
blockHeight - The width of each block to be drawn, in pixels
shader - Shader to use for OpenGL ES 2.0
Method Detail

render

public void render()
Renders the entire map. Use this function only on very small maps or for debugging purposes.


render

public void render(int x,
                   int y,
                   int width,
                   int height)
Renders all layers between the given Tiled world coordinates. This is the same as calling render(int, int, int, int, int[]) with all layers in the layers list.


render

public void render(int x,
                   int y,
                   int width,
                   int height,
                   int[] layers)
Renders specific layers between the given Tiled world coordinates.

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

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(int, int, int, int, 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(int, int, int, int, 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(int, int, int, int, 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(int, int, int, int, int[]).


getProjectionMatrix

public Matrix4 getProjectionMatrix()

getTransformMatrix

public Matrix4 getTransformMatrix()

getMapHeightPixels

public int getMapHeightPixels()

getMapWidthPixels

public int getMapWidthPixels()

getRow

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

Parameters:
worldY - the Y coordinate in pixels

getCol

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

Parameters:
worldX - the X coordinate in pixels

dispose

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

Specified by:
dispose in interface Disposable

libgdx API

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