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
ConstructorsConstructorDescriptionEffect()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(StageNode2D 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 EffectCreates an effect that will first wait for the specified period of time, and will then perform an action.voidend(SceneContext context) Clean-up logic that is performed every time the scene ends.static EffectforClickHandler(StageNode2D graphic, Runnable handler) static EffectforFrameHandler(Runnable action) Creates an effect that will use the specified callback every frame for as long the effect is active.static EffectforFrameHandler(Updatable action) Creates an effect that will use the specified callback every frame for as long the effect is active.static EffectforPrimitiveAlpha(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 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 EffectforSpriteScale(Sprite sprite, nl.colorize.util.animation.Timeline timeline) Shorthand for creating an effect that scales a sprite based on the specified timeline.static EffectforTextAlpha(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 EffectforTextAppear(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 EffectforTimeline(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 EffectforX(StageNode2D graphic, nl.colorize.util.animation.Timeline timeline) static EffectforY(StageNode2D graphic, nl.colorize.util.animation.Timeline timeline) booleanIndicates the scene has been completed and no longer wishes to receive frame updates.linkGraphics(StageNode2D... graphics) Links existing graphics to this effect.removeAfterwards(StageNode2D... graphics) Deprecated.static EffectscaleToFit(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.voidupdate(SceneContext context, float deltaTime) Called during every frame update for as long as the scene is active.<T extends StageNode2D>
voidwithLinkedGraphics(Class<T> type, Consumer<T> callback) Deprecated.voidwithLinkedGraphics(Consumer<StageNode2D> 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(StageNode2D...)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:SceneCalled during every frame update for as long as the scene is active.deltaTimeindicates the elapsed time since the last frame, in seconds. -
end
Description copied from interface:SceneClean-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:SceneIndicates 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:
isCompletedin interfaceScene
-
withLinkedGraphics
Deprecated. -
withLinkedGraphics
@Deprecated public <T extends StageNode2D> 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. Theuniformparameter controls how the sprite should handle situations where the aspect ratio ofbounddiffers 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(StageNode2D...)instead.