Package ch.swingfx.timer
Class AnimationTimer
java.lang.Object
ch.swingfx.timer.AnimationTimer
Class for simple animation. Example:
AnimationTimer at = new AnimationTimer(FrameRate.FPS_25); at.setDuration(2500); // 2500 milliseconds at.setAnimationTarget(new AnimationTarget() { public void event(AnimationTimer timer, float fraction) { // between begin and end. // fraction represents the time passed (0f = 0%, 1f = 100%) } public void begin(AnimationTimer timer) { // start of the animation } public void end(AnimationTimer timer) { // end of the animation } }); at.start();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Used withAnimationTimer
.setAnimationTarget().
Implement this interface to receive events from theAnimationTimer
static enum
Frame rates for theAnimationTimer
Note: These frame rates are approximations.private class
Handles the calculation of the time that has elapsed since the start and sends it to theAnimationTimer.AnimationTarget
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
Stores the start time of the animation so we can calculate the fractionprivate AnimationTimer.AnimationTarget
Animation events get sent to this targetprivate long
Duration of the animation in millisecondsprivate final Timer
The timer for the animation -
Constructor Summary
ConstructorsConstructorDescriptionCreates anAnimationTimer
with a default frame rate of 25Creates anAnimationTimer
with an specified frame rate -
Method Summary
Modifier and TypeMethodDescriptionvoid
Set the animation targetvoid
setDuration
(long duration) Set the duration of the animationvoid
start()
Start the animationvoid
stop()
End the animation before duration has passed
-
Field Details
-
fTimer
The timer for the animation -
fAnimationTarget
Animation events get sent to this target -
fAnimationStartTime
private long fAnimationStartTimeStores the start time of the animation so we can calculate the fraction -
fDuration
private long fDurationDuration of the animation in milliseconds
-
-
Constructor Details
-
AnimationTimer
public AnimationTimer()Creates anAnimationTimer
with a default frame rate of 25 -
AnimationTimer
Creates anAnimationTimer
with an specified frame rate- Parameters:
fps
-AnimationTimer.FrameRate
we want to use for thisAnimationTimer
-
-
Method Details
-
setDuration
public void setDuration(long duration) Set the duration of the animation- Parameters:
duration
- the duration of the animation
-
start
public void start()Start the animation -
stop
public void stop()End the animation before duration has passed -
setAnimationTarget
Set the animation target- Parameters:
target
- the animation target
-