Class AnimationController
- All Implemented Interfaces:
IAnimationController
,IUpdateable
- Direct Known Subclasses:
EntityAnimationController
public class AnimationController
extends java.lang.Object
implements IAnimationController
Constructor Summary
Constructors Constructor Description AnimationController()
Initializes a new instance of theAnimationController
class.AnimationController(Animation defaultAnimation)
Initializes a new instance of theAnimationController
class with the specified default animation.AnimationController(Animation defaultAnimation, Animation... animations)
Initializes a new instance of theAnimationController
class with the specified default animation.AnimationController(Spritesheet sprite)
Initializes a new instance of theAnimationController
class with the specified default animation.AnimationController(Spritesheet sprite, boolean loop)
Initializes a new instance of theAnimationController
class with the specified default animation.Method Summary
Modifier and Type Method Description void
add(Animation animation)
Add the specifiedAnimation
to this controller instance.void
add(ImageEffect effect)
Adds the specifiedImageEffect
to be applied when the current image is retrieved from this controller.void
addListener(AnimationListener listener)
Adds the specified animation listener to receive events and callbacks when animation playbacks are started and finished.void
attach()
Attach theAnimationController
, as well as all itsAnimation
s to the Game loop.protected java.lang.String
buildCurrentCacheKey()
Build a unique cache key for the current frame.void
clear()
Remove allAnimation
s from theAnimationController
.void
detach()
Detach theAnimationController
, as well as all itsAnimation
s from the Game loop.static Animation
flipAnimation(Animation anim, java.lang.String newSpriteName)
Animation
get(java.lang.String animationName)
Gets theAnimation
instance with the specified name from this controller.java.awt.geom.AffineTransform
getAffineTransform()
Gets theAffineTransform
instance assigned to this controller that can be used to externally transform the current image when rendering it with theImageRenderer
.java.util.Collection<Animation>
getAll()
Gets allAnimation
instances managed by this controller.Animation
getCurrent()
Gets the currently activeAnimation
of this controller.java.awt.image.BufferedImage
getCurrentImage()
Gets the current sprite (keyframe) of the currently active animation of this controller.java.awt.image.BufferedImage
getCurrentImage(int width, int height)
Gets the current sprite scaled by the specified dimensions of the currently active animation of this controller.Animation
getDefault()
Gets the defaultAnimation
of this controller.java.util.List<ImageEffect>
getImageEffects()
Gets all image effects assigned to this controller.boolean
hasAnimation(java.lang.String animationName)
Determines whether this controller has anAnimation
with the specified name.boolean
isEnabled()
Determines whether this controller is currently enabled.boolean
isPlaying(java.lang.String animationName)
Determines whether this controller is currently playing anAnimation
with the specified name.void
play(java.lang.String animationName)
Plays theAnimation
with the specified name.void
remove(Animation animation)
Removes the specifiedAnimation
from this controller instance.void
remove(ImageEffect effect)
Removes the specifiedImageEffect
from this controller.void
removeListener(AnimationListener listener)
Removes the specified animation listener.void
setAffineTransform(java.awt.geom.AffineTransform affineTransform)
Sets theAffineTransform
instance for this controller that can be used to externally transform the current image when rendering it with theImageRenderer
.void
setDefault(Animation defaultAnimation)
Sets the specifiedAnimation
as default for this controller.void
setEnabled(boolean enabled)
Sets a flag that defines whether this controller is enabled or not.void
update()
This method is called by the game loop on all objects that are attached to the loop.
Constructor Details
AnimationController
public AnimationController()Initializes a new instance of theAnimationController
class.AnimationController
Initializes a new instance of theAnimationController
class with the specified default animation.- Parameters:
defaultAnimation
- The default animation for this controller.- See Also:
getDefault()
AnimationController
Initializes a new instance of theAnimationController
class with the specified default animation.- Parameters:
defaultAnimation
- The default animation for this controller.animations
- Additional animations that are managed by this controller instance.- See Also:
getDefault()
,getAll()
AnimationController
Initializes a new instance of theAnimationController
class with the specified default animation.- Parameters:
sprite
- The sprite sheet used by the default animation of this controller.
AnimationController
Initializes a new instance of theAnimationController
class with the specified default animation.- Parameters:
sprite
- The sprite sheet used by the default animation of this controller.loop
- A flag indicating whether the default animation should be looped or only played once.
Method Details
flipAnimation
add
Description copied from interface:IAnimationController
Add the specifiedAnimation
to this controller instance.Animations with the same name will be replaced by this method.
- Specified by:
add
in interfaceIAnimationController
- Parameters:
animation
- The animation to add.- See Also:
IAnimationController.remove(Animation)
,IAnimationController.hasAnimation(String)
,IAnimationController.clear()
add
Description copied from interface:IAnimationController
Adds the specifiedImageEffect
to be applied when the current image is retrieved from this controller.- Specified by:
add
in interfaceIAnimationController
- Parameters:
effect
- The image effect to be added.
addListener
Description copied from interface:IAnimationController
Adds the specified animation listener to receive events and callbacks when animation playbacks are started and finished.- Specified by:
addListener
in interfaceIAnimationController
- Parameters:
listener
- The listener to add.
attach
public void attach()Attach theAnimationController
, as well as all itsAnimation
s to the Game loop.- See Also:
ILoop
clear
public void clear()Description copied from interface:IAnimationController
Remove allAnimation
s from theAnimationController
.- Specified by:
clear
in interfaceIAnimationController
detach
public void detach()Detach theAnimationController
, as well as all itsAnimation
s from the Game loop.- See Also:
ILoop
get
Description copied from interface:IAnimationController
Gets theAnimation
instance with the specified name from this controller.The name of an
Animation
is case sensitive.- Specified by:
get
in interfaceIAnimationController
- Parameters:
animationName
- The name of the animation.- Returns:
- The animation with the specified name or null if no such animation is managed by this controller.
- See Also:
IAnimationController.getCurrent()
,IAnimationController.getDefault()
,IAnimationController.hasAnimation(String)
getAffineTransform
public java.awt.geom.AffineTransform getAffineTransform()Description copied from interface:IAnimationController
Gets theAffineTransform
instance assigned to this controller that can be used to externally transform the current image when rendering it with theImageRenderer
.- Specified by:
getAffineTransform
in interfaceIAnimationController
- Returns:
- The
AffineTransform
instance assigned to this controller or null. - See Also:
AffineTransform
,ImageRenderer.renderTransformed(java.awt.Graphics2D, java.awt.Image, AffineTransform)
,IAnimationController.setAffineTransform(AffineTransform)
,IAnimationController.getCurrentImage()
getAll
Description copied from interface:IAnimationController
Gets allAnimation
instances managed by this controller.- Specified by:
getAll
in interfaceIAnimationController
- Returns:
- All
Animation
instances.
getCurrent
Description copied from interface:IAnimationController
Gets the currently activeAnimation
of this controller.The current active animation provides the current image that is being rendered by consumers of this controller (e.g. the render engine or any explicit, custom render mechanism).
- Specified by:
getCurrent
in interfaceIAnimationController
- Returns:
- The currently active animation.
- See Also:
IAnimationController.getDefault()
,IAnimationController.get(String)
,RenderEngine.renderEntity(java.awt.Graphics2D, de.gurkenlabs.litiengine.entities.IEntity)
getCurrentImage
public java.awt.image.BufferedImage getCurrentImage()Description copied from interface:IAnimationController
Gets the current sprite (keyframe) of the currently active animation of this controller.The implementation of this method applies all registered
ImageEffects
.- Specified by:
getCurrentImage
in interfaceIAnimationController
- Returns:
- The current sprite of the current animation with applied effects; or null, if this controller is currently disabled.
- See Also:
IAnimationController.getCurrent()
,Animation.getCurrentKeyFrame()
,IAnimationController.isEnabled()
getCurrentImage
public java.awt.image.BufferedImage getCurrentImage(int width, int height)Description copied from interface:IAnimationController
Gets the current sprite scaled by the specified dimensions of the currently active animation of this controller.The implementation of this method applies all registered
ImageEffects
.- Specified by:
getCurrentImage
in interfaceIAnimationController
- Parameters:
width
- The width of the image.height
- The height of the image.- Returns:
- The current sprite of the current animation scaled by the defined dimensions with applied effects; or null, if this controller is currently disabled.
- See Also:
IAnimationController.getCurrent()
,IAnimationController.getCurrentImage()
,Animation.getCurrentKeyFrame()
,IAnimationController.isEnabled()
getDefault
Description copied from interface:IAnimationController
Gets the defaultAnimation
of this controller.This animation is played when no other animation is currently active.
- Specified by:
getDefault
in interfaceIAnimationController
- Returns:
- The default animation of this controller.
- See Also:
IAnimationController.getCurrent()
,IAnimationController.get(String)
,IAnimationController.setDefault(Animation)
getImageEffects
Description copied from interface:IAnimationController
Gets all image effects assigned to this controller.- Specified by:
getImageEffects
in interfaceIAnimationController
- Returns:
- All image effects of this controller.
- See Also:
IAnimationController.add(ImageEffect)
,IAnimationController.remove(ImageEffect)
hasAnimation
public boolean hasAnimation(java.lang.String animationName)Description copied from interface:IAnimationController
Determines whether this controller has anAnimation
with the specified name.The name of an
Animation
is case sensitive.- Specified by:
hasAnimation
in interfaceIAnimationController
- Parameters:
animationName
- The name of the animation.- Returns:
- True if this controller contains an
Animation
with the specified name; otherwise false. - See Also:
IAnimationController.add(Animation)
,IAnimationController.remove(Animation)
isEnabled
public boolean isEnabled()Description copied from interface:IAnimationController
Determines whether this controller is currently enabled.- Specified by:
isEnabled
in interfaceIAnimationController
- Returns:
- True if this controller is enabled; otherwise false.
isPlaying
public boolean isPlaying(java.lang.String animationName)Description copied from interface:IAnimationController
Determines whether this controller is currently playing anAnimation
with the specified name.The name of an
Animation
is case sensitive.- Specified by:
isPlaying
in interfaceIAnimationController
- Parameters:
animationName
- The name of the animation.- Returns:
- True if this controller is currently playing the
Animation
with the specified name. - See Also:
IAnimationController.getCurrent()
play
public void play(java.lang.String animationName)Description copied from interface:IAnimationController
Plays theAnimation
with the specified name.Does nothing if this controller doesn't contain an
Animation
with the specified name.This method also publishes the "played" event to all subscribed
AnimationListener
instances.- Specified by:
play
in interfaceIAnimationController
- Parameters:
animationName
- The name of theAnimation
to be played.- See Also:
AnimationListener.played(Animation)
,IAnimationController.getCurrent()
remove
Description copied from interface:IAnimationController
Removes the specifiedAnimation
from this controller instance.- Specified by:
remove
in interfaceIAnimationController
- Parameters:
animation
- The animation to remove.- See Also:
IAnimationController.add(Animation)
,IAnimationController.hasAnimation(String)
,IAnimationController.clear()
remove
Description copied from interface:IAnimationController
Removes the specifiedImageEffect
from this controller.- Specified by:
remove
in interfaceIAnimationController
- Parameters:
effect
- The image effect to be removed.
removeListener
Description copied from interface:IAnimationController
Removes the specified animation listener.- Specified by:
removeListener
in interfaceIAnimationController
- Parameters:
listener
- The listener to remove.
setAffineTransform
public void setAffineTransform(java.awt.geom.AffineTransform affineTransform)Description copied from interface:IAnimationController
Sets theAffineTransform
instance for this controller that can be used to externally transform the current image when rendering it with theImageRenderer
.- Specified by:
setAffineTransform
in interfaceIAnimationController
- Parameters:
affineTransform
- TheAffineTransform
instance for this controller.- See Also:
AffineTransform
,IAnimationController.getAffineTransform()
setDefault
Description copied from interface:IAnimationController
Sets the specifiedAnimation
as default for this controller.- Specified by:
setDefault
in interfaceIAnimationController
- Parameters:
defaultAnimation
- The animation to be set as default.- See Also:
IAnimationController.getDefault()
setEnabled
public void setEnabled(boolean enabled)Description copied from interface:IAnimationController
Sets a flag that defines whether this controller is enabled or not.- Specified by:
setEnabled
in interfaceIAnimationController
- Parameters:
enabled
- True if the controller should be enabled; otherwise false.
update
public void update()Description copied from interface:IUpdateable
This method is called by the game loop on all objects that are attached to the loop. It's called on every tick of the loop and the frequency can be configured using theClientConfiguration
.- Specified by:
update
in interfaceIUpdateable
- See Also:
ClientConfiguration.setMaxFps(int)
buildCurrentCacheKey
protected java.lang.String buildCurrentCacheKey()Build a unique cache key for the current frame. The spritesheet'shashCode
, the current keyframe's sprite index, as well as all appliedImageEffect
s' names, are considered when determining the current cache key.- Returns:
- the unique cache key for the current key frame