Package paintingcanvas.animation
Class Animation
- java.lang.Object
-
- paintingcanvas.animation.Animation
-
- Direct Known Subclasses:
ColorAnimation
,MovementAnimation
,OpacityAnimation
,RotationAnimation
public abstract class Animation extends java.lang.Object
A class that stores information about animations transitions
-
-
Field Summary
Fields Modifier and Type Field Description int
duration
The length of the animation in framesEasing
easing
The easing function to useint
startFrame
The frame at which the animation should start
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ColorAnimation
colorTo(int hex)
Create an animation that changes the color ofthis
to the specifiedcolor
.static ColorAnimation
colorTo(int r, int g, int b)
Create an animation that changes the color ofthis
to the specifiedcolor
.static ColorAnimation
colorTo(int r, int g, int b, int a)
Create an animation that changes the color ofthis
to the specifiedcolor
.static Animation
colorTo(java.awt.Color color)
Create an animation that changes the color ofthis
to the specifiedcolor
.static ColorAnimation
colorTo(java.lang.String name)
Create an animation that changes the color ofthis
to the specifiedcolor
.static ColorAnimation
colorTo(Hue hue)
Create an animation that changes the color ofthis
to the specifiedcolor
.abstract Animation
copy()
Animation
easing(Easing easing)
Sets the easing to be used by this animationboolean
ended(int frame)
static OpacityAnimation
fadeIn()
Create an animation that fadesthis
in.static OpacityAnimation
fadeOut()
Create an animation that fadesthis
out.protected abstract void
initAnimation(Drawable<?> drawable)
Initialize the animation with the affected drawablestatic MovementAnimation
moveBy(int x, int y)
Create an animation that movesthis
by the specifiedx
andy
static MovementAnimation
moveHorizontalBy(int x)
Create an animation that movesthis
by the specifiedx
horizontally.static MovementAnimation
moveTo(int x, int y)
Create an animation that movesthis
to the specifiedx
andy
static MovementAnimation
moveVerticalBy(int y)
Create an animation that movesthis
by the specifiedy
vertically.static RotationAnimation
rotateBy(double angle)
Create an animation that rotatesthis
byangle
degrees.static RotationAnimation
rotateTo(double angle)
Create an animation that rotatesthis
to the specifiedangle
degrees.void
update(int frame)
Updates the animation with the current frameprotected abstract void
updateAnimation(Drawable<?> drawable, double progress)
update the animation with the progress (0-1) and affected drawable
-
-
-
Field Detail
-
startFrame
public int startFrame
The frame at which the animation should start
-
duration
public int duration
The length of the animation in frames
-
easing
public Easing easing
The easing function to use
-
-
Method Detail
-
moveTo
public static MovementAnimation moveTo(int x, int y)
Create an animation that movesthis
to the specifiedx
andy
Circle c = new Circle(200, 200, 50); // the circle will slowly move to (100, 100) over 3 seconds c.animate().add(Animation.moveTo(100, 100), 3);
- Parameters:
x
- the x position to move toy
- the y position to move to- Returns:
- a
MovementAnimation
-
colorTo
public static ColorAnimation colorTo(int r, int g, int b)
Create an animation that changes the color ofthis
to the specifiedcolor
. See Wikipedia for how this works.Circle c = new Circle(200, 200, 50); // the circle will slowly turn red over 3 seconds c.animate().add(Animation.colorTo(255, 0, 0), 3);
- Parameters:
r
- red (0-255)g
- green (0-255)b
- blue (0-255)- Returns:
- a
ColorAnimation
-
colorTo
public static ColorAnimation colorTo(int r, int g, int b, int a)
Create an animation that changes the color ofthis
to the specifiedcolor
. See Wikipedia for how this works.Circle c = new Circle(200, 200, 50); // the circle will slowly turn red with with 100/255 opacity over three seconds c.animate().add(Animation.colorTo(255, 0, 0), 3);
- Parameters:
r
- red (0-255)g
- green (0-255)b
- blue (0-255)a
- alpha (0-255)- Returns:
- a
ColorAnimation
-
colorTo
public static ColorAnimation colorTo(int hex)
Create an animation that changes the color ofthis
to the specifiedcolor
. See Wikipedia for how this works.Circle c = new Circle(200, 200, 50); // the circle will slowly turn red over three seconds c.animate().add(Animation.colorTo(0xFF0000), 3);
- Parameters:
hex
- the number describing the RGB color- Returns:
- a
ColorAnimation
-
colorTo
public static ColorAnimation colorTo(Hue hue)
Create an animation that changes the color ofthis
to the specifiedcolor
.Circle c = new Circle(200, 200, 50); // the circle will turn red, and then blue c.colorTo(0xFF0000, 3).colorTo(0x0000FF, 3);
- Parameters:
hue
- the hue- Returns:
- a
ColorAnimation
-
colorTo
public static ColorAnimation colorTo(java.lang.String name)
Create an animation that changes the color ofthis
to the specifiedcolor
.Circle c = new Circle(200, 200, 50); // the circle will slowly turn red over 3 seconds // then, the circle will slowly turn blue over 3 seconds c.animate().add(Animation.colorTo("red"), 3).add(Animation.colorTo("#0000FF"), 3);
- Parameters:
name
- the hue name or the hex code- Returns:
- a
ColorAnimation
-
colorTo
public static Animation colorTo(java.awt.Color color)
Create an animation that changes the color ofthis
to the specifiedcolor
. SeeColor
for the full list of colors, and constructors for this classCircle c = new Circle(200, 200, 50); // the circle will turn slowly red over 3 seconds c.animate().add(Animation.colorTo(Color.RED, 3));
- Parameters:
color
- the color to fade to- Returns:
- an
Animation
-
fadeOut
public static OpacityAnimation fadeOut()
Create an animation that fadesthis
out.Circle c = new Circle(200, 200, 50); // the circle will slowly fade out over 3 seconds c.animate().add(Animation.fadeOut(), 3);
- Returns:
- an
OpacityAnimation
- See Also:
fadeIn()
-
fadeIn
public static OpacityAnimation fadeIn()
Create an animation that fadesthis
in.Circle c = new Circle(200, 200, 50); // the circle will slowly fade out over 3 seconds // then, fade back in over 3 seconds c.animate().add(Animation.fadeOut(), 3).add(Animation.fadeIn(), 3);
- Returns:
- an
OpacityAnimation
- See Also:
fadeOut()
-
rotateTo
public static RotationAnimation rotateTo(double angle)
Create an animation that rotatesthis
to the specifiedangle
degrees. If you supply an angle> 360
it will make more than one full rotation.Square s = new Square(200, 200, 50); // the square will slowly rotate one turn counter-clockwise over 3 seconds // then, slowly rotate two turns clockwise over 3 seconds c.animate().add(Animation.rotateTo(360), 3).add(Animation.rotateTo(-360), 3);
- Parameters:
angle
- The absolute angle to rotate to in degrees.- Returns:
- a
RotationAnimation
-
rotateBy
public static RotationAnimation rotateBy(double angle)
Create an animation that rotatesthis
byangle
degrees.Square s = new Square(200, 200, 50); // the square will slowly rotate one turn counter-clockwise over 3 seconds // then, slowly rotate one turn clockwise over 3 seconds c.animate().add(Animation.rotateBy(360), 3).add(Animation.rotateBy(-360), 3);
- Parameters:
angle
- The relative angle to rotate to in degrees.- Returns:
- a
RotationAnimation
-
moveBy
public static MovementAnimation moveBy(int x, int y)
Create an animation that movesthis
by the specifiedx
andy
Circle c = new Circle(200, 200, 50); // the circle will slowly move down 100 over 3 seconds // then, slowly move right over 3 seconds c.animate().add(Animation.moveTo(0, 100), 3).add(Animation.moveTo(200, 0), 3);
- Parameters:
x
- the x to move byy
- the y to move by- Returns:
- a
MovementAnimation
-
moveHorizontalBy
public static MovementAnimation moveHorizontalBy(int x)
Create an animation that movesthis
by the specifiedx
horizontally. Positive values move right, negative values move left. This method is equivalent tomoveBy(x, 0)
Circle c = new Circle(200, 200, 50); // the circle will move slowly right 300 pixels over 3 seconds c.animate().add(Animation.moveHorizontalBy(100), 3);
- Parameters:
x
- the x to move by- Returns:
- an
AnimationBuilder
-
moveVerticalBy
public static MovementAnimation moveVerticalBy(int y)
Create an animation that movesthis
by the specifiedy
vertically. Positive values move down, negative values move up. This method is equivalent tomoveBy(0, y)
Circle c = new Circle(200, 200, 50); // the circle will move right 300 pixels over 3 seconds c.animate().add(Animation.moveVerticalBy(100), 3);
- Parameters:
y
- the y to move by- Returns:
- an
AnimationBuilder
-
copy
public abstract Animation copy()
-
easing
public Animation easing(Easing easing)
Sets the easing to be used by this animation- Parameters:
easing
- the easing to be used- Returns:
- this
-
update
public void update(int frame)
Updates the animation with the current frame- Parameters:
frame
- the current frame
-
updateAnimation
protected abstract void updateAnimation(Drawable<?> drawable, double progress)
update the animation with the progress (0-1) and affected drawable- Parameters:
drawable
- The affected drawableprogress
- Animation progress (0-1)
-
initAnimation
protected abstract void initAnimation(Drawable<?> drawable)
Initialize the animation with the affected drawable- Parameters:
drawable
- The affected drawable
-
ended
public boolean ended(int frame)
-
-