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)  
    • 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)
        Create an animation that moves this to the specified x and y
        
         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 to
        y - 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 of this to the specified color. 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 of this to the specified color. 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 of this to the specified color. 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 of this to the specified color.
        
         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 of this to the specified color.
        
         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 of this to the specified color. See Color for the full list of colors, and constructors for this class
        
         Circle 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 fades this 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 fades this 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 rotates this to the specified angle 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 rotates this by angle 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 moves this by the specified x and y
        
         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 by
        y - the y to move by
        Returns:
        a MovementAnimation
      • moveHorizontalBy

        public static MovementAnimation moveHorizontalBy​(int x)
        Create an animation that moves this by the specified x horizontally. Positive values move right, negative values move left. This method is equivalent to moveBy(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 moves this by the specified y vertically. Positive values move down, negative values move up. This method is equivalent to moveBy(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
      • 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)