Class AnimationController
- All Implemented Interfaces:
IAnimationController,IUpdateable
- Direct Known Subclasses:
EntityAnimationController
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes a new instance of theAnimationControllerclass.AnimationController(Animation defaultAnimation) Initializes a new instance of theAnimationControllerclass with the specified default animation.AnimationController(Animation defaultAnimation, Animation... animations) Initializes a new instance of theAnimationControllerclass with the specified default animation.AnimationController(Spritesheet sprite) Initializes a new instance of theAnimationControllerclass with the specified default animation.AnimationController(Spritesheet sprite, boolean loop) Initializes a new instance of theAnimationControllerclass with the specified default animation. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the specifiedAnimationto this controller instance.voidadd(ImageEffect effect) Adds the specifiedImageEffectto be applied when the current image is retrieved from this controller.voidaddListener(AnimationListener listener) Adds the specified animation listener to receive events and callbacks when animation playbacks are started and finished.voidattach()Attach theAnimationController, as well as all itsAnimations to the Game loop.protected StringBuild a unique cache key for the current frame.voidclear()Remove allAnimations from theAnimationController.voiddetach()Detach theAnimationController, as well as all itsAnimations from the Game loop.static AnimationflippedAnimation(Animation anim, String newSpriteName, boolean vertical) Creates a new animation with the sprites flipped either vertically or horizontally.Gets theAnimationinstance with the specified name from this controller.Gets theAffineTransforminstance assigned to this controller that can be used to externally transform the current image when rendering it with theImageRenderer.getAll()Gets allAnimationinstances managed by this controller.Gets the currently activeAnimationof this controller.Gets the current sprite (keyframe) of the currently active animation of this controller.getCurrentImage(int width, int height) Gets the current sprite scaled by the specified dimensions of the currently active animation of this controller.Gets the defaultAnimationof this controller.Gets all image effects assigned to this controller.booleanhasAnimation(String animationName) Determines whether this controller has anAnimationwith the specified name.booleanDetermines whether this controller is currently enabled.booleanDetermines whether this controller is currently playing anAnimationwith the specified name.voidPlays theAnimationwith the specified name.voidRemoves the specifiedAnimationfrom this controller instance.voidremove(ImageEffect effect) Removes the specifiedImageEffectfrom this controller.voidremoveListener(AnimationListener listener) Removes the specified animation listener.voidsetAffineTransform(AffineTransform affineTransform) Sets theAffineTransforminstance for this controller that can be used to externally transform the current image when rendering it with theImageRenderer.voidsetDefault(Animation defaultAnimation) Sets the specifiedAnimationas default for this controller.voidsetEnabled(boolean enabled) Sets a flag that defines whether this controller is enabled or not.voidupdate()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 theAnimationControllerclass. -
AnimationController
Initializes a new instance of theAnimationControllerclass with the specified default animation.- Parameters:
defaultAnimation- The default animation for this controller.- See Also:
-
AnimationController
Initializes a new instance of theAnimationControllerclass 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:
-
AnimationController
Initializes a new instance of theAnimationControllerclass with the specified default animation.- Parameters:
sprite- The sprite sheet used by the default animation of this controller.
-
AnimationController
Initializes a new instance of theAnimationControllerclass 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
-
flippedAnimation
Creates a new animation with the sprites flipped either vertically or horizontally.- Parameters:
anim- The original animation to be flipped.newSpriteName- The name for the new flipped spritesheet.vertical- A boolean flag indicating whether to flip the sprites vertically. If false, the sprites will be flipped horizontally.- Returns:
- A new Animation object with the flipped sprites.
-
add
Description copied from interface:IAnimationControllerAdd the specifiedAnimationto this controller instance.Animations with the same name will be replaced by this method.
- Specified by:
addin interfaceIAnimationController- Parameters:
animation- The animation to add.- See Also:
-
add
Description copied from interface:IAnimationControllerAdds the specifiedImageEffectto be applied when the current image is retrieved from this controller.- Specified by:
addin interfaceIAnimationController- Parameters:
effect- The image effect to be added.
-
addListener
Description copied from interface:IAnimationControllerAdds the specified animation listener to receive events and callbacks when animation playbacks are started and finished.- Specified by:
addListenerin interfaceIAnimationController- Parameters:
listener- The listener to add.
-
attach
public void attach()Attach theAnimationController, as well as all itsAnimations to the Game loop.- See Also:
-
clear
public void clear()Description copied from interface:IAnimationControllerRemove allAnimations from theAnimationController.- Specified by:
clearin interfaceIAnimationController
-
detach
public void detach()Detach theAnimationController, as well as all itsAnimations from the Game loop.- See Also:
-
get
Description copied from interface:IAnimationControllerGets theAnimationinstance with the specified name from this controller.The name of an
Animationis case sensitive.- Specified by:
getin 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:
-
getAffineTransform
Description copied from interface:IAnimationControllerGets theAffineTransforminstance assigned to this controller that can be used to externally transform the current image when rendering it with theImageRenderer.- Specified by:
getAffineTransformin interfaceIAnimationController- Returns:
- The
AffineTransforminstance assigned to this controller or null. - See Also:
-
getAll
Description copied from interface:IAnimationControllerGets allAnimationinstances managed by this controller.- Specified by:
getAllin interfaceIAnimationController- Returns:
- All
Animationinstances.
-
getCurrent
Description copied from interface:IAnimationControllerGets the currently activeAnimationof 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:
getCurrentin interfaceIAnimationController- Returns:
- The currently active animation.
- See Also:
-
getCurrentImage
Description copied from interface:IAnimationControllerGets the current sprite (keyframe) of the currently active animation of this controller.The implementation of this method applies all registered
ImageEffects.- Specified by:
getCurrentImagein interfaceIAnimationController- Returns:
- The current sprite of the current animation with applied effects; or null, if this controller is currently disabled.
- See Also:
-
getCurrentImage
Description copied from interface:IAnimationControllerGets 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:
getCurrentImagein 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:
-
getDefault
Description copied from interface:IAnimationControllerGets the defaultAnimationof this controller.This animation is played when no other animation is currently active.
- Specified by:
getDefaultin interfaceIAnimationController- Returns:
- The default animation of this controller.
- See Also:
-
getImageEffects
Description copied from interface:IAnimationControllerGets all image effects assigned to this controller.- Specified by:
getImageEffectsin interfaceIAnimationController- Returns:
- All image effects of this controller.
- See Also:
-
hasAnimation
Description copied from interface:IAnimationControllerDetermines whether this controller has anAnimationwith the specified name.The name of an
Animationis case sensitive.- Specified by:
hasAnimationin interfaceIAnimationController- Parameters:
animationName- The name of the animation.- Returns:
- True if this controller contains an
Animationwith the specified name; otherwise false. - See Also:
-
isEnabled
public boolean isEnabled()Description copied from interface:IAnimationControllerDetermines whether this controller is currently enabled.- Specified by:
isEnabledin interfaceIAnimationController- Returns:
- True if this controller is enabled; otherwise false.
-
isPlaying
Description copied from interface:IAnimationControllerDetermines whether this controller is currently playing anAnimationwith the specified name.The name of an
Animationis case sensitive.- Specified by:
isPlayingin interfaceIAnimationController- Parameters:
animationName- The name of the animation.- Returns:
- True if this controller is currently playing the
Animationwith the specified name. - See Also:
-
play
Description copied from interface:IAnimationControllerPlays theAnimationwith the specified name.Does nothing if this controller doesn't contain an
Animationwith the specified name.This method also publishes the "played" event to all subscribed
AnimationListenerinstances.- Specified by:
playin interfaceIAnimationController- Parameters:
animationName- The name of theAnimationto be played.- See Also:
-
remove
Description copied from interface:IAnimationControllerRemoves the specifiedAnimationfrom this controller instance.- Specified by:
removein interfaceIAnimationController- Parameters:
animation- The animation to remove.- See Also:
-
remove
Description copied from interface:IAnimationControllerRemoves the specifiedImageEffectfrom this controller.- Specified by:
removein interfaceIAnimationController- Parameters:
effect- The image effect to be removed.
-
removeListener
Description copied from interface:IAnimationControllerRemoves the specified animation listener.- Specified by:
removeListenerin interfaceIAnimationController- Parameters:
listener- The listener to remove.
-
setAffineTransform
Description copied from interface:IAnimationControllerSets theAffineTransforminstance for this controller that can be used to externally transform the current image when rendering it with theImageRenderer.- Specified by:
setAffineTransformin interfaceIAnimationController- Parameters:
affineTransform- TheAffineTransforminstance for this controller.- See Also:
-
setDefault
Description copied from interface:IAnimationControllerSets the specifiedAnimationas default for this controller.- Specified by:
setDefaultin interfaceIAnimationController- Parameters:
defaultAnimation- The animation to be set as default.- See Also:
-
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:IAnimationControllerSets a flag that defines whether this controller is enabled or not.- Specified by:
setEnabledin interfaceIAnimationController- Parameters:
enabled- True if the controller should be enabled; otherwise false.
-
update
public void update()Description copied from interface:IUpdateableThis 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:
updatein interfaceIUpdateable- See Also:
-
buildCurrentCacheKey
Build a unique cache key for the current frame. The spritesheet'shashCode, the current keyframe's sprite index, as well as all appliedImageEffects' names, are considered when determining the current cache key.- Returns:
- the unique cache key for the current key frame
-