Class Animation

    • Field Summary

      Fields 
      Modifier and Type Field Description
      int duration
      The length of the animation in frames
      Easing easing
      The easing function to use
      int startFrame
      The frame at which the animation should start
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Animation()  
      protected Animation​(int startFrame, int duration)  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static ColorAnimation colorTo​(int hex)
      Creates an animation that changes the color of this to the specified color over duration seconds.
      static ColorAnimation colorTo​(int r, int g, int b)
      Creates an animation that changes the color of this to the specified color over duration seconds.
      static Animation colorTo​(java.awt.Color color)
      Creates an animation that changes the color of this to the specified color over duration seconds.
      abstract Animation copy()  
      Animation easing​(Easing easing)
      Sets the easing to be used by this animation
      boolean ended​(int frame)  
      static OpacityAnimation fadeIn()
      Creates an animation that fades this in over @{code duration} seconds.
      static OpacityAnimation fadeOut()
      Creates an animation that fades this out over @{code duration} seconds.
      protected abstract void initAnimation​(Drawable<?> drawable)
      Initialize the animation with the affected drawable
      static MovementAnimation moveBy​(int x, int y)
      Creates an animation that moves this by the specified x and y
      static MovementAnimation moveTo​(int x, int y)
      Creates an animation that moves this to the specified x and y over duration seconds
      static RotationAnimation rotateBy​(int angle)
      Creates an animation that rotates this by angle°.
      static RotationAnimation rotateTo​(int angle)
      Creates an animation that rotates this to the specified angle°.
      void update​(int frame)
      Updates the animation with the current frame
      protected abstract void updateAnimation​(Drawable<?> drawable, double progress)
      update the animation with the progress (0-1) and affected drawable
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • Animation

        protected Animation​(int startFrame,
                            int duration)
      • Animation

        protected Animation()
    • Method Detail

      • moveTo

        public static MovementAnimation moveTo​(int x,
                                               int y)
        Creates an animation that moves this to the specified x and y over duration seconds
        
         Circle c = new Circle(200, 200, 50);
         // the circle will move to (100, 100), and then to (200, 200)
         c.moveTo(100, 100, 3).moveTo(200, 200, 3);
         
        Parameters:
        x - the x-position to move to
        y - the y-position to move to
        Returns:
        a MovementAnimation
      • colorTo

        public static ColorAnimation colorTo​(int r,
                                             int g,
                                             int b)
        Creates an animation that changes the color of this to the specified color over duration seconds. See Wikipedia for how this works.
        
         Circle c = new Circle(200, 200, 50);
         // the circle will turn red, and then blue
         c.colorTo(255, 0, 0, 3).colorTo(0, 0, 255, 3);
         
        Parameters:
        r - red (0-255)
        g - green (0-255)
        b - blue (0-255)
        Returns:
        a ColorAnimation
      • colorTo

        public static ColorAnimation colorTo​(int hex)
        Creates an animation that changes the color of this to the specified color over duration seconds. See Wikipedia for how this works.
        
         Circle c = new Circle(200, 200, 50);
         // the circle will turn red, and then blue
         c.colorTo(0xFF0000, 3).colorTo(0x0000FF, 3);
         
        Parameters:
        hex - The number describing the RGB color
        Returns:
        a ColorAnimation
      • colorTo

        public static Animation colorTo​(java.awt.Color color)
        Creates an animation that changes the color of this to the specified color over duration seconds. See Color for the full list of colors, and constructors for this class
        
         Circle c = new Circle(200, 200, 50);
         // the circle will turn red, and then blue
         c.colorTo(Color.RED, 3).colorTo(Color.BLUE, 3);
         
        Parameters:
        color - The color to fade to
        Returns:
        an Animation
      • fadeOut

        public static OpacityAnimation fadeOut()
        Creates an animation that fades this out over @{code duration} seconds.
        
         Circle c = new Circle(200, 200, 50);
         // the circle will fade out, then in
         c.fadeOut(3).fadeIn(3);
         
        Returns:
        an OpacityAnimation
        See Also:
        fadeIn()
      • fadeIn

        public static OpacityAnimation fadeIn()
        Creates an animation that fades this in over @{code duration} seconds.
        
         Circle c = new Circle(200, 200, 50);
         // the circle will fade out, then in
         c.fadeOut(3).fadeIn(3);
         
        Returns:
        an OpacityAnimation
        See Also:
        fadeOut()
      • rotateTo

        public static RotationAnimation rotateTo​(int angle)
        Creates an animation that rotates this to the specified angle°. If you supply an angle > 360 it will make more than one full rotation.
        
         Square s = new Square(200, 200, 50);
         // the square will rotate one turn counter-clockwise, then 2 turns clockwise
         c.rotateTo(360, 3).colorTo(-360, 3);
         
        Parameters:
        angle - The absolute angle to rotate to in degrees.
        Returns:
        a RotationAnimation
      • rotateBy

        public static RotationAnimation rotateBy​(int angle)
        Creates an animation that rotates this by angle°.
        
         Square s = new Square(200, 200, 50);
         // the square will rotate one turn counter-clockwise, then one turns clockwise
         c.rotateTo(360, 3).colorTo(-360, 3);
         
        Parameters:
        angle - The relative angle to rotate to in degrees.
        Returns:
        a RotationAnimation
      • moveBy

        public static MovementAnimation moveBy​(int x,
                                               int y)
        Creates an animation that moves this by the specified x and y
        
         Circle c = new Circle(200, 200, 50);
         // the circle will move down 100, and then right 200
         c.moveTo(0, 100, 3).moveTo(200, 0, 3);
         
        Parameters:
        x - the x to move by
        y - the y to move by
        Returns:
        a MovementAnimation
      • 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 drawable
        progress - 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)