Class CreatureAnimationController<T extends Creature>
java.lang.Object
de.gurkenlabs.litiengine.graphics.animation.AnimationController
de.gurkenlabs.litiengine.graphics.animation.EntityAnimationController<T>
de.gurkenlabs.litiengine.graphics.animation.CreatureAnimationController<T>
- Type Parameters:
T
- The type of the creature for which animations are managed by this controller.
- All Implemented Interfaces:
IEntityController
,IAnimationController
,IEntityAnimationController<T>
,IUpdateable
public class CreatureAnimationController<T extends Creature>
extends EntityAnimationController<T>
This
AnimationController
implementation provides animation rules that
use naming conventions to provide Animation
s for Creature
implementations.
The spritesheet images need to be named according to the following
conventions in order to be automatically used by this controller:getSpritePrefix()
-idle-{DIRECTION}.{EXTENSION}getSpritePrefix()
-walk-{DIRECTION}.{EXTENSION}
Direction
enum and getSpritePrefix()
refers to the current sprite prefix of the entity.
{EXTENSION} refers to a value of the ImageFormat
enum.- See Also:
Creature
,Direction
,IEntity.getName()
Nested Class Summary
Nested classes/interfaces inherited from class de.gurkenlabs.litiengine.graphics.animation.EntityAnimationController
EntityAnimationController.AnimationRule<T extends IEntity>
Constructor Summary
Constructors Constructor Description CreatureAnimationController(T creature, boolean useFlippedSpritesAsFallback)
Initializes a new instance of theCreatureAnimationController
class.CreatureAnimationController(T creature, boolean useFlippedSpritesAsFallback, Animation defaultAnimation, Animation... animations)
Initializes a new instance of theCreatureAnimationController
class.CreatureAnimationController(T creature, Animation defaultAnimation)
Initializes a new instance of theCreatureAnimationController
class.Method Summary
Modifier and Type Method Description protected java.lang.String
getCurrentAnimationName()
This method evaluates the current animation name that depends on certain properties of theEntityAnimationController.getEntity()
.static java.lang.String
getSpriteName(Creature creature, CreatureAnimationState state)
Gets the sprite name for the specified creature and animation state.static java.lang.String
getSpriteName(Creature creature, CreatureAnimationState state, Direction direction)
Gets the sprite name for the specified creature, animation state.and direction.protected java.lang.String
getSpritePrefix()
boolean
isAutoScaling()
Gets a flag indicating whether this controller instance is auto scaling its animations by the dimensions of the entity.Methods inherited from class de.gurkenlabs.litiengine.graphics.animation.EntityAnimationController
addRule, addRule, getDefaultSpritePrefixes, getEntity, scaleSprite, scaleSprite, setAutoScaling, setSpritePrefix, update
Methods inherited from class de.gurkenlabs.litiengine.graphics.animation.AnimationController
add, add, addListener, attach, buildCurrentCacheKey, clear, detach, flipAnimation, get, getAffineTransform, getAll, getCurrent, getCurrentImage, getCurrentImage, getDefault, getImageEffects, hasAnimation, isEnabled, isPlaying, play, remove, remove, removeListener, setAffineTransform, setDefault, setEnabled
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface de.gurkenlabs.litiengine.graphics.animation.IAnimationController
add, add, addListener, clear, get, getAffineTransform, getAll, getCurrent, getCurrentImage, getCurrentImage, getDefault, getImageEffects, hasAnimation, isEnabled, isPlaying, play, remove, remove, removeListener, setAffineTransform, setDefault, setEnabled
Constructor Details
CreatureAnimationController
Initializes a new instance of theCreatureAnimationController
class.- Parameters:
creature
- The creature related to this controller.useFlippedSpritesAsFallback
- A flag indicating whether this controller should flip the provided spritesheet horizontally to provide a fallback animation for left or right directions.- See Also:
EntityAnimationController.getEntity()
CreatureAnimationController
Initializes a new instance of theCreatureAnimationController
class.- Parameters:
creature
- The creature related to this controller.defaultAnimation
- The default animation for this controller.- See Also:
EntityAnimationController.getEntity()
,AnimationController.getDefault()
CreatureAnimationController
public CreatureAnimationController(T creature, boolean useFlippedSpritesAsFallback, Animation defaultAnimation, Animation... animations)Initializes a new instance of theCreatureAnimationController
class.- Parameters:
creature
- The creature related to this controller.useFlippedSpritesAsFallback
- A flag indicating whether this controller should flip the provided spritesheet horizontally to provide a fallback animation for left or right directions.defaultAnimation
- The default animation for this controller.animations
- Additional animations that are managed by this controller instance.- See Also:
EntityAnimationController.getEntity()
,AnimationController.getDefault()
,AnimationController.getAll()
Method Details
getSpriteName
Gets the sprite name for the specified creature and animation state.- Parameters:
creature
- The creature to retrieve the sprite name for.state
- The current animation state.- Returns:
- A string representing the sprite name for the specified creature in the defined animation state.
- See Also:
Creature.getSpritesheetName()
getSpriteName
public static java.lang.String getSpriteName(Creature creature, CreatureAnimationState state, Direction direction)Gets the sprite name for the specified creature, animation state.and direction.- Parameters:
creature
- The creature to retrieve the sprite name for.state
- The current animation state.direction
- The direction in which the creature is facing.- Returns:
- A string representing the sprite name for the specified creature, animation state and facing direction.
- See Also:
Creature.getSpritesheetName()
isAutoScaling
public boolean isAutoScaling()Description copied from interface:IEntityAnimationController
Gets a flag indicating whether this controller instance is auto scaling its animations by the dimensions of the entity.- Specified by:
isAutoScaling
in interfaceIEntityAnimationController<T extends Creature>
- Overrides:
isAutoScaling
in classEntityAnimationController<T extends Creature>
- Returns:
- True if this instance is automatically scaling to the dimensions of the entity; otherwise false.
getSpritePrefix
protected java.lang.String getSpritePrefix()- Overrides:
getSpritePrefix
in classEntityAnimationController<T extends Creature>
getCurrentAnimationName
protected java.lang.String getCurrentAnimationName()This method evaluates the current animation name that depends on certain properties of theEntityAnimationController.getEntity()
. Overwriting this method allows to specify more sophisticated animations.- Returns:
- The name of the current animation that should be played