Class OrthoCachedTiledMapRenderer
- java.lang.Object
-
- com.badlogic.gdx.maps.tiled.renderers.OrthoCachedTiledMapRenderer
-
- All Implemented Interfaces:
MapRenderer,TiledMapRenderer,Disposable
public class OrthoCachedTiledMapRenderer extends java.lang.Object implements TiledMapRenderer, Disposable
Renders ortho tiles by caching geometry on the GPU. How much is cached is controlled bysetOverCache(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.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanblendingprotected RectanglecacheBoundsprotected booleancachedprotected booleancanCacheMoreEprotected booleancanCacheMoreNprotected booleancanCacheMoreSprotected booleancanCacheMoreWprotected intcountprotected TiledMapmapprotected floatmaxTileHeightprotected floatmaxTileWidthprotected static intNUM_VERTICESprotected floatoverCacheprotected SpriteCachespriteCacheprotected floatunitScaleprotected float[]verticesprotected RectangleviewBounds
-
Constructor Summary
Constructors Constructor Description OrthoCachedTiledMapRenderer(TiledMap map)Creates a renderer with a unit scale of 1 and cache size of 2000.OrthoCachedTiledMapRenderer(TiledMap map, float unitScale)Creates a renderer with a cache size of 2000.OrthoCachedTiledMapRenderer(TiledMap map, float unitScale, int cacheSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Releases all resources of this object.SpriteCachegetSpriteCache()voidinvalidateCache()Causes the cache to be rebuilt the next time it is rendered.booleanisCached()Returns true if tiles are currently cached.voidrender()Renders all the layers of a map.voidrender(int[] layers)Renders the given layers of a map.voidrenderImageLayer(TiledMapImageLayer layer)voidrenderObject(MapObject object)voidrenderObjects(MapLayer layer)voidrenderTileLayer(TiledMapTileLayer layer)voidsetBlending(boolean blending)voidsetMaxTileSize(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.voidsetOverCache(float overCache)Sets the percentage of the view that is cached in each direction.voidsetView(OrthographicCamera camera)Sets the projection matrix and viewbounds from the given camera.voidsetView(Matrix4 projection, float x, float y, float width, float height)Sets the projection matrix for rendering, as well as the bounds of the map which should be rendered.
-
-
-
Field Detail
-
NUM_VERTICES
protected static final int NUM_VERTICES
- See Also:
- Constant Field Values
-
map
protected final TiledMap map
-
spriteCache
protected final SpriteCache spriteCache
-
vertices
protected final float[] vertices
-
blending
protected boolean blending
-
unitScale
protected float unitScale
-
viewBounds
protected final Rectangle viewBounds
-
cacheBounds
protected final Rectangle cacheBounds
-
overCache
protected float overCache
-
maxTileWidth
protected float maxTileWidth
-
maxTileHeight
protected float maxTileHeight
-
cached
protected boolean cached
-
count
protected int count
-
canCacheMoreN
protected boolean canCacheMoreN
-
canCacheMoreE
protected boolean canCacheMoreE
-
canCacheMoreW
protected boolean canCacheMoreW
-
canCacheMoreS
protected boolean canCacheMoreS
-
-
Constructor Detail
-
OrthoCachedTiledMapRenderer
public OrthoCachedTiledMapRenderer(TiledMap map)
Creates a renderer with a unit scale of 1 and cache size of 2000.
-
OrthoCachedTiledMapRenderer
public OrthoCachedTiledMapRenderer(TiledMap map, float unitScale)
Creates a renderer with a cache size of 2000.
-
OrthoCachedTiledMapRenderer
public OrthoCachedTiledMapRenderer(TiledMap map, float unitScale, int cacheSize)
- Parameters:
cacheSize- The maximum number of tiles that can be cached.
-
-
Method Detail
-
setView
public void setView(OrthographicCamera camera)
Description copied from interface:MapRendererSets 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.- Specified by:
setViewin interfaceMapRenderer- Parameters:
camera- theOrthographicCamera
-
setView
public void setView(Matrix4 projection, float x, float y, float width, float height)
Description copied from interface:MapRendererSets 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.- Specified by:
setViewin interfaceMapRenderer
-
render
public void render()
Description copied from interface:MapRendererRenders all the layers of a map.- Specified by:
renderin interfaceMapRenderer
-
render
public void render(int[] layers)
Description copied from interface:MapRendererRenders the given layers of a map.- Specified by:
renderin interfaceMapRenderer- Parameters:
layers- the layers to render.
-
renderObjects
public void renderObjects(MapLayer layer)
- Specified by:
renderObjectsin interfaceTiledMapRenderer
-
renderObject
public void renderObject(MapObject object)
- Specified by:
renderObjectin interfaceTiledMapRenderer
-
renderTileLayer
public void renderTileLayer(TiledMapTileLayer layer)
- Specified by:
renderTileLayerin interfaceTiledMapRenderer
-
renderImageLayer
public void renderImageLayer(TiledMapImageLayer layer)
- Specified by:
renderImageLayerin interfaceTiledMapRenderer
-
invalidateCache
public void invalidateCache()
Causes the cache to be rebuilt the next time it is rendered.
-
isCached
public boolean isCached()
Returns true if tiles are currently cached.
-
setOverCache
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.
-
setMaxTileSize
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 possiblysetOverCache(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.
-
setBlending
public void setBlending(boolean blending)
-
getSpriteCache
public SpriteCache getSpriteCache()
-
dispose
public void dispose()
Description copied from interface:DisposableReleases all resources of this object.- Specified by:
disposein interfaceDisposable
-
-