Class AnimatedSprite

java.lang.Object
Sprite
AnimatedSprite

public class AnimatedSprite extends Sprite
Animated Sprite class - useful to have Sprites move around Designed to be used with Spritesheets & JSON Array files from TexturePacker software: https://free-tex-packer.com/app/ Inspired by Daniel Shiffman's p5js Animated Sprite tutorial: https://youtu.be/3noMeuufLZY
  • Constructor Details

    • AnimatedSprite

      public AnimatedSprite(processing.core.PApplet p, String png, String json, float x, float y, float aSpeed)
      Constructor #1 for AnimatedSprite with Spritesheet (Must use the TexturePacker to make the JSON)
      Parameters:
      p - Processing applet
      png - spritesheet file generated from TexturePacker (See instructions for how to generate)
      json - json data file generated from TexturePacker (See instructions for how to generate)
      x - sets the initial LEFT edge of the Sprite
      y - sets the initial TOP edge of the Sprite
      aSpeed - how quickly the animations will cycle
    • AnimatedSprite

      public AnimatedSprite(processing.core.PApplet p, String png, String json, float x, float y)
      Constructor #2: animations + starting coordinates
      Parameters:
      p - Processing applet
      png - spritesheet file generated from TexturePacker (See instructions for how to generate)
      json - json data file generated from TexturePacker (See instructions for how to generate)
      x - sets the initial LEFT edge of the Sprite
      y - sets the initial TOP edge of the Sprite
    • AnimatedSprite

      public AnimatedSprite(processing.core.PApplet p, String png, String json)
      Constructor #3 taking in images and json only
      Parameters:
      p - Processing applet
      png - spritesheet file generated from TexturePacker (See instructions for how to generate)
      json - json data file generated from TexturePacker (See instructions for how to generate)
  • Method Details

    • show

      public void show()
      Overriden method Displays the correct frame of the Sprite image on the screen
      Overrides:
      show in class Sprite
    • setSpeed

      public void setSpeed(float animationSpeed)
      Sets the speed of how fast the frames cycle
      Parameters:
      animationSpeed -
    • animate

      public void animate(float animationSpeed)
      Cycles through the images of the animated sprite & reset a new animation speed
      Parameters:
      animationSpeed -
    • animate

      public void animate()
      Cycles through the images of the animated sprite
    • animateMove

      public void animateMove(float hSpeed, float vSpeed, float animationSpeed, boolean wraparound)
      Makes animated sprite move in any straight line + sets animation speed
      Parameters:
      hSpeed - horizontal speed of the Sprite
      vSpeed - vertical speed of the Sprite
      animationSpeed - how quickly the animations will cycle
      wraparound - true if animated sprite will appear on the other side of the screen after travelling off the screen
    • animateMove

      public void animateMove(float hSpeed, float vSpeed, boolean wraparound)
      Makes animated sprite move in any straight line
      Parameters:
      hSpeed - horizontal speed of the Sprite
      vSpeed - vertical speed of the Sprite
      wraparound - true if animated sprite will appear on the other side of the screen after travelling off the screen
    • animateHorizontal

      public void animateHorizontal(float horizontalSpeed, float animationSpeed, boolean wraparound)
      Makes the AnimatedSprite move to the right-left
      Parameters:
      horizontalSpeed - horizontal speed of the Sprite
      animationSpeed - how quickly the animations will cycle
      wraparound - true if animated sprite will appear on the other side of the screen after travelling off the screen
    • animateVertical

      public void animateVertical(float verticalSpeed, float animationSpeed, boolean wraparound)
      Makes the AnimatedSprite move up-down
      Parameters:
      verticalSpeed - vertical speed of the Sprite
      animationSpeed - how quickly the animations will cycle
      wraparound - true if animated sprite will appear on the other side of the screen after travelling off the screen
    • animateToPlayer

      public void animateToPlayer(AnimatedSprite otherAS, float animationSpeed, boolean wraparound)
      Makes the AnimatedSprite move in the direction of another AnimatedSprite
      Parameters:
      otherAS - another AnimatedSprite
      animationSpeed - how quickly the animations will cycle
      wraparound - true if animated sprite will appear on the other side of the screen after travelling off the screen
    • getJsonFile

      public String getJsonFile()
      Accessor method
      Returns:
      String the JSON file's path
    • setAnimationSpeed

      public void setAnimationSpeed(float animationSpeed)
      Mutator method
      Parameters:
      animationSpeed - how quickly the animations will cycle
    • resize

      public void resize(int w, int h)
      Resizes the animated sprite images to different dimensions
      Overrides:
      resize in class Sprite
      Parameters:
      w - width of the newly sized AnimatedSprite
      h - height of the newly sized AnimatedSprite
    • copySprite

      public AnimatedSprite copySprite()
      Copies an AnimatedSprite
      Returns:
      AnimatedSprite new copy of this AnimatedSprite
    • copyTo

      public AnimatedSprite copyTo(float x, float y)
      Copies an AnimatedSprite to a specific location
      Overrides:
      copyTo in class Sprite
      Parameters:
      x - the LEFT edge of the copied ASprite
      y - the TOP edge of the copied ASprite
      Returns:
      AnimatedSprite new copy of this AnimatedSprite
    • copyTo

      public AnimatedSprite copyTo(float x, float y, float aSpeed)
      Copies an AnimatedSprite to a specific location with a new speed
      Parameters:
      x - the LEFT edge of the copied ASprite
      y - the TOP edge of the copied ASprite
      aSpeed - how quickly the animations will cycle
      Returns:
      AnimatedSprite new copy of this AnimatedSprite