Class Effect

  • All Implemented Interfaces:
    Renderable, Updatable

    public abstract class Effect
    extends java.lang.Object
    implements Updatable, Renderable
    An animated graphical effect that can be played as part of a scene. In combination with the EffectManager, this allows declarative effects that can be played without having to manually update their logic and graphics every frame.

    The effect consists of the graphics that are animated according to the timeline. A number of modifiers can be added to the effect, that will use the timeline's current value to update how the effect should be displayed. These modifiers are represented by callback functions, that are called every frame based on the timeline's current value. The effect's graphics are then rendered based on its updated state.

    There are two types of effects that can be created using the factory methods in this class. The first are "plain" effects that do not define any behavior. The second are shorthand versions, for example to move a sprite or to change text's alpha value. Note that these shorthand effects can still be extended by adding additional modifiers, so that more complex effects can be created from these starting points.

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static Effect forAnimation​(Animation anim, nl.colorize.util.animation.Timeline timeline)  
      static Effect forImage​(Image image, nl.colorize.util.animation.Timeline timeline)  
      static Effect forSprite​(Sprite sprite, nl.colorize.util.animation.Timeline timeline)  
      static Effect forSpriteAlpha​(Sprite sprite, nl.colorize.util.animation.Timeline timeline)
      Shorthand for creating an effect that modifies the sprite's alpha value based on a timeline.
      static Effect forSpriteRotation​(Sprite sprite, float duration)
      Shorthand for creating an effect that rotates a sprite.
      static Effect forSpriteX​(Sprite sprite, nl.colorize.util.animation.Timeline timeline)
      Shorthand for creating an effect that modifies the sprite's X position based on a timeline.
      static Effect forSpriteY​(Sprite sprite, nl.colorize.util.animation.Timeline timeline)
      Shorthand for creating an effect that modifies the sprite's Y position based on a timeline.
      static Effect forText​(java.lang.String text, TTFont font, Align align, nl.colorize.util.animation.Timeline timeline)  
      static Effect forTextAlpha​(java.lang.String text, TTFont font, Align align, nl.colorize.util.animation.Timeline timeline)
      Shorthand for creating an effect that modifies the text's alpha value based on a timeline.
      static Effect forTextAppear​(java.lang.String text, TTFont font, Align align, float duration)
      Shorthand for creating an effect that will make the text slowly appear over time, with more and more characters appearing on screen over time until the entire text is shown.
      Point getPosition()  
      Transform getTransform()  
      boolean isCompleted()  
      void modify​(java.util.function.Consumer<java.lang.Float> modifier)
      Registers a callback function that will be called during every frame update, with the effect's current timeline value as the argument.
      abstract void render​(GraphicsContext graphics)  
      void setPosition​(float x, float y)  
      void setPosition​(Point position)  
      void setTransform​(Transform transform)  
      void update​(float deltaTime)
      Updates this object for the current frame.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • modify

        public void modify​(java.util.function.Consumer<java.lang.Float> modifier)
        Registers a callback function that will be called during every frame update, with the effect's current timeline value as the argument. The callback can then be used to update the effect's graphical appearance.
      • setPosition

        public void setPosition​(Point position)
      • setPosition

        public void setPosition​(float x,
                                float y)
      • getPosition

        public Point getPosition()
      • setTransform

        public void setTransform​(Transform transform)
      • getTransform

        public Transform getTransform()
      • update

        public void update​(float deltaTime)
        Description copied from interface: Updatable
        Updates this object for the current frame.
        Specified by:
        update in interface Updatable
        Parameters:
        deltaTime - Elapsed time since the last frame, in seconds.
      • isCompleted

        public boolean isCompleted()
      • forSprite

        public static Effect forSprite​(Sprite sprite,
                                       nl.colorize.util.animation.Timeline timeline)
      • forSpriteX

        public static Effect forSpriteX​(Sprite sprite,
                                        nl.colorize.util.animation.Timeline timeline)
        Shorthand for creating an effect that modifies the sprite's X position based on a timeline.
      • forSpriteY

        public static Effect forSpriteY​(Sprite sprite,
                                        nl.colorize.util.animation.Timeline timeline)
        Shorthand for creating an effect that modifies the sprite's Y position based on a timeline.
      • forSpriteRotation

        public static Effect forSpriteRotation​(Sprite sprite,
                                               float duration)
        Shorthand for creating an effect that rotates a sprite.
      • forSpriteAlpha

        public static Effect forSpriteAlpha​(Sprite sprite,
                                            nl.colorize.util.animation.Timeline timeline)
        Shorthand for creating an effect that modifies the sprite's alpha value based on a timeline.
      • forAnimation

        public static Effect forAnimation​(Animation anim,
                                          nl.colorize.util.animation.Timeline timeline)
      • forImage

        public static Effect forImage​(Image image,
                                      nl.colorize.util.animation.Timeline timeline)
      • forText

        public static Effect forText​(java.lang.String text,
                                     TTFont font,
                                     Align align,
                                     nl.colorize.util.animation.Timeline timeline)
      • forTextAppear

        public static Effect forTextAppear​(java.lang.String text,
                                           TTFont font,
                                           Align align,
                                           float duration)
        Shorthand for creating an effect that will make the text slowly appear over time, with more and more characters appearing on screen over time until the entire text is shown.
      • forTextAlpha

        public static Effect forTextAlpha​(java.lang.String text,
                                          TTFont font,
                                          Align align,
                                          nl.colorize.util.animation.Timeline timeline)
        Shorthand for creating an effect that modifies the text's alpha value based on a timeline.