Class Effect
- java.lang.Object
-
- nl.colorize.multimedialib.scene.Action
-
- nl.colorize.multimedialib.scene.Effect
-
public abstract class Effect extends Action implements Drawable
An animated graphical effect that can be played as part of a scene. In combination with theActionManager, 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 Summary
Constructors Modifier Constructor Description protectedEffect(nl.colorize.util.animation.Timeline timeline)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static EffectforAnimation(Animation anim, float duration)static EffectforAnimation(Animation anim, nl.colorize.util.animation.Timeline timeline)static EffectforImage(Image image, float duration)static EffectforImage(Image image, nl.colorize.util.animation.Timeline timeline)static EffectforSprite(Sprite sprite, nl.colorize.util.animation.Timeline timeline)static EffectforSpriteAlpha(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 EffectforSpriteRotation(Sprite sprite, float duration)Shorthand for creating an effect that rotates a sprite.static EffectforSpriteX(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 EffectforSpriteY(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 EffectforText(java.lang.String text, TTFont font, Align align, nl.colorize.util.animation.Timeline timeline)static EffectforTextAlpha(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 EffectforTextAppear(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.Point2DgetPosition()TransformgetTransform()booleanisCompleted()Effectmodify(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.EffectmodifyFrameUpdate(Updatable modifier)Registers a callback function that is updated every frame.EffectonComplete(java.lang.Runnable observer)Registers a callback function that will be notified once this effect has been completed.abstract voidrender(GraphicsContext2D graphics)voidsetPosition(float x, float y)voidsetPosition(Point2D position)voidsetTransform(Transform transform)voidupdate(float deltaTime)Updates this object for the current frame.-
Methods inherited from class nl.colorize.multimedialib.scene.Action
chain, indefinitely, isActive, onCompleted, onFrame, onFrame, onStart, timed, until
-
-
-
-
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 usingmodify(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:UpdatableUpdates this object for the current frame.
-
isCompleted
public boolean isCompleted()
- Overrides:
isCompletedin classAction
-
render
public abstract void render(GraphicsContext2D graphics)
-
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)
-
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.
-
-