APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.maps.tiled.renderers

public Class OrthoCachedTiledMapRenderer

extends Object
implements TiledMapRenderer, Disposable
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.utils.Disposable, com.badlogic.gdx.maps.tiled.TiledMapRenderer, com.badlogic.gdx.maps.MapRenderer
Static Imports
com.badlogic.gdx.graphics.g2d.Batch.*

Renders ortho tiles by caching geometry on the GPU. How much is cached is controlled by setOverCache(float). When the view reaches the edge of the cached tiles, the cache is rebuilt at the new view position.

This class may have poor performance when tiles are often changed dynamically, since the cache must be rebuilt after each change.

Authors
Justin Shapcott, Nathan Sweet

Field Summary

Modifier and TypeField and Description
protected boolean
protected final Rectangle
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected int
protected Rectangle
protected final TiledMap
protected float
protected float
protected static final int
protected float
protected final SpriteCache
private static final float
protected float
protected final float[]
protected final Rectangle

Constructor Summary

AccessConstructor and Description
public
OrthoCachedTiledMapRenderer(TiledMap map)

Creates a renderer with a unit scale of 1 and cache size of 2000.

public
OrthoCachedTiledMapRenderer(TiledMap map, float unitScale)

Creates a renderer with a cache size of 2000.

public
OrthoCachedTiledMapRenderer(TiledMap map, float unitScale, int
The maximum number of tiles that can be cached.
cacheSize
)

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources of this object.

public SpriteCache
public void
invalidateCache()

Causes the cache to be rebuilt the next time it is rendered.

public boolean
isCached()

Returns true if tiles are currently cached.

public void
render()

Implements com.badlogic.gdx.maps.MapRenderer.render.

Renders all the layers of a map.

public void
render(int[] layers)

Implements com.badlogic.gdx.maps.MapRenderer.render.

Renders the given layers of a map.

public void
public void
public void
public void
public void
setBlending(boolean blending)

public void
setMaxTileSize(float maxPixelWidth, float maxPixelHeight)

Expands the view size in each direction, ensuring that tiles of this size or smaller are never culled from the visible portion of the view.

public void
setOverCache(float overCache)

Sets the percentage of the view that is cached in each direction.

public void
setView(OrthographicCamera camera)

Implements com.badlogic.gdx.maps.MapRenderer.setView.

Sets the projection matrix and viewbounds from the given camera.

public void
setView(Matrix4 projection, float x, float y, float width, float height)

Implements com.badlogic.gdx.maps.MapRenderer.setView.

Sets the projection matrix for rendering, as well as the bounds of the map which should be rendered.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blendingback to summary
protected boolean blending
cacheBoundsback to summary
protected final Rectangle cacheBounds
cachedback to summary
protected boolean cached
canCacheMoreEback to summary
protected boolean canCacheMoreE
canCacheMoreNback to summary
protected boolean canCacheMoreN
canCacheMoreSback to summary
protected boolean canCacheMoreS
canCacheMoreWback to summary
protected boolean canCacheMoreW
countback to summary
protected int count
imageBoundsback to summary
protected Rectangle imageBounds
mapback to summary
protected final TiledMap map
maxTileHeightback to summary
protected float maxTileHeight
maxTileWidthback to summary
protected float maxTileWidth
NUM_VERTICESback to summary
protected static final int NUM_VERTICES
overCacheback to summary
protected float overCache
spriteCacheback to summary
protected final SpriteCache spriteCache
toleranceback to summary
private static final float tolerance
unitScaleback to summary
protected float unitScale
verticesback to summary
protected final float[] vertices
viewBoundsback to summary
protected final Rectangle viewBounds

Constructor Detail

OrthoCachedTiledMapRendererback to summary
public OrthoCachedTiledMapRenderer(TiledMap map)

Creates a renderer with a unit scale of 1 and cache size of 2000.

OrthoCachedTiledMapRendererback to summary
public OrthoCachedTiledMapRenderer(TiledMap map, float unitScale)

Creates a renderer with a cache size of 2000.

OrthoCachedTiledMapRendererback to summary
public OrthoCachedTiledMapRenderer(TiledMap map, float unitScale, int cacheSize)
Parameters
cacheSize:int

The maximum number of tiles that can be cached.

Method Detail

disposeback to summary
public void dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Doc from com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources of this object.

Annotations
@Override
getSpriteCacheback to summary
public SpriteCache getSpriteCache()
invalidateCacheback to summary
public void invalidateCache()

Causes the cache to be rebuilt the next time it is rendered.

isCachedback to summary
public boolean isCached()

Returns true if tiles are currently cached.

renderback to summary
public void render()

Implements com.badlogic.gdx.maps.MapRenderer.render.

Doc from com.badlogic.gdx.maps.MapRenderer.render.

Renders all the layers of a map.

Annotations
@Override
renderback to summary
public void render(int[] layers)

Implements com.badlogic.gdx.maps.MapRenderer.render.

Doc from com.badlogic.gdx.maps.MapRenderer.render.

Renders the given layers of a map.

Annotations
@Override
renderImageLayerback to summary
public void renderImageLayer(TiledMapImageLayer layer)

Implements com.badlogic.gdx.maps.tiled.TiledMapRenderer.renderImageLayer.

Annotations
@Override
renderObjectback to summary
public void renderObject(MapObject object)

Implements com.badlogic.gdx.maps.tiled.TiledMapRenderer.renderObject.

Annotations
@Override
renderObjectsback to summary
public void renderObjects(MapLayer layer)

Implements com.badlogic.gdx.maps.tiled.TiledMapRenderer.renderObjects.

Annotations
@Override
renderTileLayerback to summary
public void renderTileLayer(TiledMapTileLayer layer)

Implements com.badlogic.gdx.maps.tiled.TiledMapRenderer.renderTileLayer.

Annotations
@Override
setBlendingback to summary
public void setBlending(boolean blending)
setMaxTileSizeback to summary
public void setMaxTileSize(float maxPixelWidth, float maxPixelHeight)

Expands the view size in each direction, ensuring that tiles of this size or smaller are never culled from the visible portion of the view. Default is 0,0.

The amount of tiles cached is computed using (view size + max tile size) * overCache, meaning the max tile size increases the amount cached and possibly setOverCache(float) can be reduced.

If the view size and setOverCache(float) are configured so the size of the cached tiles is always larger than the largest tile size, this setting is not needed.

setOverCacheback to summary
public void setOverCache(float overCache)

Sets the percentage of the view that is cached in each direction. Default is 0.5.

Eg, 0.75 will cache 75% of the width of the view to the left and right of the view, and 75% of the height of the view above and below the view.

setViewback to summary
public void setView(OrthographicCamera camera)

Implements com.badlogic.gdx.maps.MapRenderer.setView.

Doc from com.badlogic.gdx.maps.MapRenderer.setView.

Sets the projection matrix and viewbounds from the given camera. If the camera changes, you have to call this method again. The viewbounds are taken from the camera's position and viewport size as well as the scale. This method will only work if the camera's direction vector is (0,0,-1) and its up vector is (0, 1, 0), which are the defaults.

Annotations
@Override
setViewback to summary
public void setView(Matrix4 projection, float x, float y, float width, float height)

Implements com.badlogic.gdx.maps.MapRenderer.setView.

Doc from com.badlogic.gdx.maps.MapRenderer.setView.

Sets the projection matrix for rendering, as well as the bounds of the map which should be rendered. Make sure that the frustum spanned by the projection matrix coincides with the viewbounds.

Annotations
@Override