Class Animation

  • All Implemented Interfaces:
    Constants, java.lang.Cloneable

    public class Animation
    extends java.lang.Object
    implements java.lang.Cloneable, Constants
    This class handles loading the images and animating the sprite
    • Constructor Detail

      • Animation

        public Animation()
        Initialize the sprite
    • Method Detail

      • scaleImage

        public static java.awt.image.BufferedImage scaleImage​(java.awt.image.BufferedImage image,
                                                              int width,
                                                              int height)
        Scale an image
        Parameters:
        image - The image to scale
        width - The new width
        height - The new height
        Returns:
        Returns the scaled image
      • getXOffset

        public int getXOffset()
        Get the offset of x for the sprite
        Returns:
        Returns the x offset in pixels
      • getYOffset

        public int getYOffset()
        Get the offset of y for the sprite
        Returns:
        Returns the y offset in pixels
      • setYOffset

        public void setYOffset​(int yOffset)
        Set the y offset manually instead of using the automatically detected value
        Parameters:
        yOffset - The new y offset
      • addImage

        public void addImage​(Animation.Direction direction,
                             java.lang.String path)
        Add an image to the animation
        Parameters:
        direction - The direction to add the image to
        path - The path to the sprite e.g. res/player/image.png
      • addImage

        public void addImage​(Animation.Direction direction,
                             java.awt.image.BufferedImage bufferedImage)
        Add an image to the animation
        Parameters:
        direction - The direction to add the image to
        bufferedImage - The path to the sprite e.g. res/player/image.png
      • getFrame

        public java.awt.image.BufferedImage getFrame()
                                              throws AnimationException
        Returns the current frame in the sprite
        Returns:
        Returns the current frame
        Throws:
        AnimationException - Thrown when there are no images in the sprite
      • getFrameCount

        public int getFrameCount()
                          throws AnimationException
        Get the number of frames in the
        Returns:
        Returns the amount of frames in the sprite
        Throws:
        AnimationException - Thrown if there are no images in the animation
      • getCurrentFrame

        public int getCurrentFrame()
                            throws AnimationException
        Get the current frame
        Returns:
        Returns the current frame
        Throws:
        AnimationException - Thrown if there are no frame in the current animation
      • setCurrentFrame

        public void setCurrentFrame​(int frame)
                             throws AnimationException
        Set which frame is to be shown in the sprite manually
        Parameters:
        frame - The frame to show
        Throws:
        AnimationException - Thrown if the frame number does not exist
      • getNextFrame

        public void getNextFrame()
                          throws AnimationException
        Returns the next frame in the sprite
        Throws:
        AnimationException - Thrown when there are no images in the sprite
      • getCurrentDirection

        public Animation.Direction getCurrentDirection()
        Get the current direction that the animation is using
        Returns:
        Returns the current direction
      • setCurrentDirection

        public void setCurrentDirection​(Animation.Direction currentDirection)
        Change the animation to the new direction and set the current frame to 0
        Parameters:
        currentDirection - The new direction
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Enable the sprite to be cloned into various cells
        Overrides:
        clone in class java.lang.Object
        Returns:
        The cloned sprite
        Throws:
        java.lang.CloneNotSupportedException - Thrown if the object does not support cloning