Class Effect

  • All Implemented Interfaces:
    Drawable, Updatable

    public abstract class Effect
    extends Action
    implements Drawable
    An animated graphical effect that can be played as part of a scene. In combination with the ActionManager, 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.

    Observers can be added to the effect, and will be notified when the effect has completed. This makes it easier to schedule follow-up events without having to poll the status of the event every frame.

    • Constructor Detail

      • Effect

        protected Effect​(nl.colorize.util.animation.Timeline timeline)
    • Method Detail

      • modify

        public Effect 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.
        Returns:
        This, for method chaining.
      • modifyFrameUpdate

        public Effect modifyFrameUpdate​(Updatable modifier)
        Registers a callback function that is updated every frame. Unlike "regular" modifiers registered using modify(Consumer), these callbacks do not use the current timeline value.
        Returns:
        This, for method chaining.
      • onComplete

        public Effect onComplete​(java.lang.Runnable observer)
        Registers a callback function that will be notified once this effect has been completed.
        Returns:
        This, for method chaining.
      • setPosition

        public void setPosition​(Point2D position)
      • setPosition

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

        public Point2D 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
        Overrides:
        update in class Action
        Parameters:
        deltaTime - Elapsed time since the last frame, in seconds.
      • isCompleted

        public boolean isCompleted()
        Overrides:
        isCompleted in class Action
      • 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)
      • forAnimation

        public static Effect forAnimation​(Animation anim,
                                          float duration)
      • forImage

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

        public static Effect forImage​(Image image,
                                      float duration)
      • 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.