Class Effect
- All Implemented Interfaces:
Scene
Behavior can be added to effects in the form of handlers. These handlers operate on different points in the effect's lifecycle, for example during frame updates or after the effect is marked as completed.
Effects can be "linked" to graphics. When the effect ends, it will automatically remove all linked graphics from the stage. This allows the effect to control the life cycle for both the effect logic and the associated graphics.
-
Constructor Summary
ConstructorDescriptionEffect()
Creates a new effect that initially does not define any behavior and is not linked to any graphics. -
Method Summary
Modifier and TypeMethodDescriptionaddClickHandler
(Supplier<Rect> bounds, Runnable handler) addClickHandler
(Rect bounds, Runnable handler) addClickHandler
(Graphic2D graphic, Runnable handler) addCompletionHandler
(Runnable handler) addFrameHandler
(Runnable handler) addFrameHandler
(Updatable handler) addTimelineHandler
(nl.colorize.util.animation.Timeline timeline, Consumer<Float> callback) Adds a frame handler that will update the specified timeline during every frame update, then invokes the callback function based on the timeline's new value.addTimerHandler
(Timer timer, Consumer<Float> callback) Adds a frame handler that will update the specified timer during every update, then invokes the callback function based on the timer's new value.attach
(SceneContext context) Attaches this effect to the specified scene context.static Effect
Creates an effect that will first wait for the specified period of time, and will then perform an action.void
end
(SceneContext context) Clean-up logic that is performed every time the scene ends.static Effect
forClickHandler
(Graphic2D graphic, Runnable handler) static Effect
forFrameHandler
(Runnable action) Creates an effect that will use the specified callback every frame for as long the effect is active.static Effect
forFrameHandler
(Updatable action) Creates an effect that will use the specified callback every frame for as long the effect is active.static Effect
forPrimitiveAlpha
(Primitive primitive, nl.colorize.util.animation.Timeline timeline) Shorthand for creating an effect that modifies the primitive's alpha value based on a 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
forSpriteScale
(Sprite sprite, nl.colorize.util.animation.Timeline timeline) Shorthand for creating an effect that scales a sprite based on the specified timeline.static Effect
forTextAlpha
(Text text, 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
(Text text, 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.static Effect
forTimeline
(nl.colorize.util.animation.Timeline timeline, Consumer<Float> callback) Creates an effect that will invoke a callback function based on the timeline's current value.static Effect
static Effect
boolean
Indicates the scene has been completed and no longer wishes to receive frame updates.linkGraphics
(Graphic2D... graphics) Links existing graphics to this effect.removeAfterwards
(Graphic2D... graphics) Deprecated.static Effect
scaleToFit
(Sprite sprite, Canvas canvas, boolean uniform) Changes a sprite's scale until it fits the canvas.stopAfter
(float duration) Adds a handler that will mark the effect as completed once the specified period of time has elapsed.stopAfterAnimation
(Sprite sprite) Adds a handler that will mark the effect as completed once the specified sprite animation has ended.stopIf
(BooleanSupplier condition) Adds a handler that will mark the effect as completed once the specified condition is met.Adds a handler that will always return false, and will therefore make the effect continue indefinitely.stopNow()
Adds a handler that will mark the effect as completed during the next frame update.void
update
(SceneContext context, float deltaTime) Called during every frame update for as long as the scene is active.<T extends Graphic2D>
voidwithLinkedGraphics
(Class<T> type, Consumer<T> callback) Deprecated.void
withLinkedGraphics
(Consumer<Graphic2D> callback) Deprecated.
-
Constructor Details
-
Effect
public Effect()Creates a new effect that initially does not define any behavior and is not linked to any graphics. Prefer using the static factory methods to create effects with the desired behavior.
-
-
Method Details
-
addFrameHandler
-
addFrameHandler
-
addTimerHandler
Adds a frame handler that will update the specified timer during every update, then invokes the callback function based on the timer's new value. This effect will be marked as completed once the timer ends. -
addTimelineHandler
public Effect addTimelineHandler(nl.colorize.util.animation.Timeline timeline, Consumer<Float> callback) Adds a frame handler that will update the specified timeline during every frame update, then invokes the callback function based on the timeline's new value. The effect will be marked as completed once the timeline ends. -
addClickHandler
-
addClickHandler
-
addClickHandler
-
addCompletionHandler
-
stopAfter
Adds a handler that will mark the effect as completed once the specified period of time has elapsed. -
stopAfterAnimation
Adds a handler that will mark the effect as completed once the specified sprite animation has ended. -
stopIf
Adds a handler that will mark the effect as completed once the specified condition is met. -
stopNow
Adds a handler that will mark the effect as completed during the next frame update. -
stopNever
Adds a handler that will always return false, and will therefore make the effect continue indefinitely. -
linkGraphics
Links existing graphics to this effect. This means the graphics will be removed from stage when the effect has completed. -
removeAfterwards
Deprecated.UselinkGraphics(Graphic2D...)
instead.Links existing graphics to this effect. This means the graphics will be removed from stage when the effect has completed. -
update
Description copied from interface:Scene
Called during every frame update for as long as the scene is active.deltaTime
indicates the elapsed time since the last frame, in seconds. -
end
Description copied from interface:Scene
Clean-up logic that is performed every time the scene ends.This method is optional, the default implementation does nothing.
-
isCompleted
public boolean isCompleted()Description copied from interface:Scene
Indicates the scene has been completed and no longer wishes to receive frame updates.If this scene is the currently active scene, it might not actually end until a new scene is requested.
If this scene is a completed sub-scene, meaning there is a parent scene which is still active, this sub-scene will end after the current frame.
- Specified by:
isCompleted
in interfaceScene
-
withLinkedGraphics
Deprecated. -
withLinkedGraphics
@Deprecated public <T extends Graphic2D> void withLinkedGraphics(Class<T> type, Consumer<T> callback) Deprecated. -
attach
Attaches this effect to the specified scene context. Using this method is identical tosceneContext.attach(effect)
, but is more readable when creating effects using the fluent API. -
forFrameHandler
Creates an effect that will use the specified callback every frame for as long the effect is active. -
forFrameHandler
Creates an effect that will use the specified callback every frame for as long the effect is active. -
delay
Creates an effect that will first wait for the specified period of time, and will then perform an action. -
forTimeline
public static Effect forTimeline(nl.colorize.util.animation.Timeline timeline, Consumer<Float> callback) Creates an effect that will invoke a callback function based on the timeline's current value. The effect is completed once the timeline has reached the end. -
forClickHandler
-
forX
-
forY
-
forSpriteRotation
Shorthand for creating an effect that rotates a sprite. -
forSpriteScale
Shorthand for creating an effect that scales a sprite based on the specified timeline. -
forSpriteAlpha
Shorthand for creating an effect that modifies the sprite's alpha value based on a timeline. -
scaleToFit
Changes a sprite's scale until it fits the canvas. Theuniform
parameter controls how the sprite should handle situations where the aspect ratio ofbound
differs from the sprite's own aspect ratio. When true, the sprite's horizontal and vertical scale will always be set to the same values. When false, they can be different, meaning the sprite could appear as stretched or squashed in certain situations. -
forPrimitiveAlpha
public static Effect forPrimitiveAlpha(Primitive primitive, nl.colorize.util.animation.Timeline timeline) Shorthand for creating an effect that modifies the primitive's alpha value based on a timeline. -
forTextAlpha
Shorthand for creating an effect that modifies the text's alpha value based on a timeline. -
forTextAppear
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.
-
linkGraphics(Graphic2D...)
instead.