Class TileAnimator

java.lang.Object
net.dermetfan.gdx.maps.tiled.TileAnimator

public abstract class TileAnimator
extends java.lang.Object
Animates the tiles in a tile map layer by replacing them with animated tiles.
To define an animation in the map editor, put an animation property in its properties. The value should be the name of the animation, so the TileAnimator will know which tiles are frames of the same animation.
You can put a property with the desired interval for each animation in the properties of the frame that defines the position of the animation on the map. Note that you cannot define a different for each frame since this is not supported by the animated tiles.
If an animation should have their frames in a specific order, you can set an ordered property with the index as value to the frames.

Example
There are the following frames with their properties:
  1. one that's actually placed on the map to define the position and properties of its animation
    "animation": "waterfall"
    "interval": "0.33"
    "ordered": "1"
  2. the second frame (not placed on the map)
    "animation": "waterfall"
    "ordered": "2"
  3. the third frame (not placed on the map)
    "animation": "waterfall"
    "ordered": "3"
Obsolete for TMX maps since libGDX has proper support: https://github.com/libgdx/libgdx/pull/2077
  • Constructor Summary

    Constructors
    Constructor Description
    TileAnimator()  
  • Method Summary

    Modifier and Type Method Description
    static void animateLayer​(com.badlogic.gdx.maps.tiled.TiledMapTile[] tiles, com.badlogic.gdx.maps.tiled.TiledMapTileLayer layer, java.lang.String animationKey, java.lang.String orderedKey, java.lang.String intervalKey, float defaultInterval)
    animates the tiles that have the animationKey in the target layer
    static void animateLayer​(com.badlogic.gdx.maps.tiled.TiledMapTileSet tiles, com.badlogic.gdx.maps.tiled.TiledMapTileLayer target, java.lang.String animationKey, java.lang.String orderedKey, java.lang.String intervalKey, float defaultInterval)  
    static void animateLayer​(com.badlogic.gdx.utils.ObjectMap<java.lang.String,​com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile>> animations, com.badlogic.gdx.maps.tiled.TiledMapTileLayer layer, java.lang.String animationKey, java.lang.String intervalKey, float defaultInterval)
    animates the target layer using the given animations
    static com.badlogic.gdx.utils.ObjectMap<java.lang.String,​com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile>> filterFrames​(com.badlogic.gdx.maps.tiled.TiledMapTile[] tiles, java.lang.String animationKey)
    filters the tiles that are frames
    static void sortFrames​(com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile> frames, java.lang.String orderedKey)
    sorts the frames by their orderedKey value
    static com.badlogic.gdx.utils.ObjectMap<java.lang.String,​com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile>> sortFrames​(com.badlogic.gdx.utils.ObjectMap<java.lang.String,​com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile>> animations, java.lang.String orderedKey)
    sorts the frames of the animation by their orderedKey value if it exists

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TileAnimator

      public TileAnimator()
  • Method Details

    • animateLayer

      public static void animateLayer​(com.badlogic.gdx.maps.tiled.TiledMapTile[] tiles, com.badlogic.gdx.maps.tiled.TiledMapTileLayer layer, java.lang.String animationKey, java.lang.String orderedKey, java.lang.String intervalKey, float defaultInterval)
      animates the tiles that have the animationKey in the target layer
      Parameters:
      tiles - the tiles to create animated tiles from
      layer - the target layer
      animationKey - the key used to tell if a tile is a frame
      intervalKey - the key used to get the animation interval (duration each frame is displayed)
      orderedKey - The key used to get the frame number of a frame tile in its animation. If no value is found, the frames won't be ordered.
    • animateLayer

      public static void animateLayer​(com.badlogic.gdx.maps.tiled.TiledMapTileSet tiles, com.badlogic.gdx.maps.tiled.TiledMapTileLayer target, java.lang.String animationKey, java.lang.String orderedKey, java.lang.String intervalKey, float defaultInterval)
      See Also:
      animateLayer(TiledMapTile[], TiledMapTileLayer, String, String, String, float)
    • animateLayer

      public static void animateLayer​(com.badlogic.gdx.utils.ObjectMap<java.lang.String,​com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile>> animations, com.badlogic.gdx.maps.tiled.TiledMapTileLayer layer, java.lang.String animationKey, java.lang.String intervalKey, float defaultInterval)
      animates the target layer using the given animations
      Parameters:
      animations - the animations to use
      layer - the TiledMapTileLayer which tiles to animate
      animationKey - the key used to tell if a tile is a frame
      intervalKey - the key used to get the animation interval (duration each frame is displayed)
      defaultInterval - the interval used if no value is found for the intervalKey
    • filterFrames

      public static com.badlogic.gdx.utils.ObjectMap<java.lang.String,​com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile>> filterFrames​(com.badlogic.gdx.maps.tiled.TiledMapTile[] tiles, java.lang.String animationKey)
      filters the tiles that are frames
      Parameters:
      tiles - all tiles
      animationKey - the key used to tell if a tile is a frame
      Returns:
      an ObjectMap which values are tiles that are frames and which keys are their animation names
    • sortFrames

      public static com.badlogic.gdx.utils.ObjectMap<java.lang.String,​com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile>> sortFrames​(com.badlogic.gdx.utils.ObjectMap<java.lang.String,​com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile>> animations, java.lang.String orderedKey)
      sorts the frames of the animation by their orderedKey value if it exists
      Parameters:
      animations - the animations to sort
      orderedKey - the key of the frame property
      Returns:
      the animations with sorted frames
      See Also:
      sortFrames(Array, String)
    • sortFrames

      public static void sortFrames​(com.badlogic.gdx.utils.Array<com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile> frames, java.lang.String orderedKey)
      sorts the frames by their orderedKey value
      Parameters:
      frames - the frames to sort
      orderedKey - the key of the ordered/frame property