Class 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 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.

    • Field Detail

      • 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: MapRenderer
        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.
        Specified by:
        setView in interface MapRenderer
        Parameters:
        camera - the OrthographicCamera
      • setView

        public void setView​(Matrix4 projection,
                            float x,
                            float y,
                            float width,
                            float height)
        Description copied from interface: MapRenderer
        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.
        Specified by:
        setView in interface MapRenderer
      • render

        public void render()
        Description copied from interface: MapRenderer
        Renders all the layers of a map.
        Specified by:
        render in interface MapRenderer
      • render

        public void render​(int[] layers)
        Description copied from interface: MapRenderer
        Renders the given layers of a map.
        Specified by:
        render in interface MapRenderer
        Parameters:
        layers - the layers to render.
      • 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 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.

      • setBlending

        public void setBlending​(boolean blending)
      • dispose

        public void dispose()
        Description copied from interface: Disposable
        Releases all resources of this object.
        Specified by:
        dispose in interface Disposable