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.ObjectA class that stores information about animations transitions
-
-
Field Summary
Fields Modifier and Type Field Description intdurationThe length of the animation in framesEasingeasingThe easing function to useintstartFrameThe 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 ColorAnimationcolorTo(int hex)Create an animation that changes the color ofthisto the specifiedcolor.static ColorAnimationcolorTo(int r, int g, int b)Create an animation that changes the color ofthisto the specifiedcolor.static ColorAnimationcolorTo(int r, int g, int b, int a)Create an animation that changes the color ofthisto the specifiedcolor.static AnimationcolorTo(java.awt.Color color)Create an animation that changes the color ofthisto the specifiedcolor.static ColorAnimationcolorTo(java.lang.String name)Create an animation that changes the color ofthisto the specifiedcolor.static ColorAnimationcolorTo(Hue hue)Create an animation that changes the color ofthisto the specifiedcolor.abstract Animationcopy()Animationeasing(Easing easing)Sets the easing to be used by this animationbooleanended(int frame)static OpacityAnimationfadeIn()Create an animation that fadesthisin.static OpacityAnimationfadeOut()Create an animation that fadesthisout.protected abstract voidinitAnimation(Drawable<?> drawable)Initialize the animation with the affected drawablestatic MovementAnimationmoveBy(int x, int y)Create an animation that movesthisby the specifiedxandystatic MovementAnimationmoveHorizontalBy(int x)Create an animation that movesthisby the specifiedxhorizontally.static MovementAnimationmoveTo(int x, int y)Create an animation that movesthisto the specifiedxandystatic MovementAnimationmoveVerticalBy(int y)Create an animation that movesthisby the specifiedyvertically.static RotationAnimationrotateBy(double angle)Create an animation that rotatesthisbyangledegrees.static RotationAnimationrotateTo(double angle)Create an animation that rotatesthisto the specifiedangledegrees.voidupdate(int frame)Updates the animation with the current frameprotected abstract voidupdateAnimation(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 movesthisto the specifiedxandyCircle 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 ofthisto 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 ofthisto 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 ofthisto 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 ofthisto 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 ofthisto 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 ofthisto the specifiedcolor. SeeColorfor 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 fadesthisout.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 fadesthisin.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 rotatesthisto the specifiedangledegrees. If you supply an angle> 360it 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 rotatesthisbyangledegrees.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 movesthisby the specifiedxandyCircle 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 movesthisby the specifiedxhorizontally. 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 movesthisby the specifiedyvertically. 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)
-
-