Package net.dermetfan.gdx.maps.tiled
Class TileAnimator
java.lang.Object
net.dermetfan.gdx.maps.tiled.TileAnimator
public abstract class TileAnimator
extends java.lang.Object
Animates the tiles in a
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
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:
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:
-
one that's actually placed on the map to define the position and properties of its animation
"animation": "waterfall"
"interval": "0.33"
"ordered": "1" -
the second frame (not placed on the map)
"animation": "waterfall"
"ordered": "2" -
the third frame (not placed on the map)
"animation": "waterfall"
"ordered": "3"
-
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 layerstatic 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 thetarget layer
using the given animationsstatic 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 framesstatic 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 valuestatic 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 existsMethods 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 createanimated tiles
fromlayer
- the targetlayer
animationKey
- the key used to tell if a tile is a frameintervalKey
- 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) -
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 thetarget layer
using the given animations- Parameters:
animations
- the animations to uselayer
- theTiledMapTileLayer
which tiles to animateanimationKey
- the key used to tell if a tile is a frameintervalKey
- 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 tilesanimationKey
- 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 sortorderedKey
- 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 sortorderedKey
- the key of the ordered/frame property
-