Class Animation

java.lang.Object
ch.epfl.cs107.play.engine.actor.Animation
All Implemented Interfaces:
Graphics, Updatable

public class Animation extends Object implements Updatable, Graphics
Animation is a Frames sequence of Sprite
  • Constructor Summary

    Constructors
    Constructor
    Description
    Animation(int frameDuration, Sprite[] sprites)
    Repeated animation constructor
    Animation(int frameDuration, Sprite[] sprites, boolean repeat)
    Default Animation Constructor
    Animation(String name, int nbFrames, float width, float height, Positionable parent, int regionWidth, int regionHeight, int frameDuration, boolean repeat)
     
    Animation(String name, int nbFrames, float width, float height, Positionable parent, int regionWidth, int regionHeight, Vector anchor, int frameDuration, boolean repeat)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Animation[]
    createAnimations(int animationDuration, Sprite[][] sprites)
    Creates an array of 4 animations (one animation per orientation) the entry indexed by Orientation.dir.ordinal() is the animation corresponding to the orientation Orientation.dir.
    static Animation[]
    createAnimations(int animationDuration, Sprite[][] sprites, boolean repeat)
    Creates an array of 4 animations (one animation per orientation) the entry indexed by Orientation.dir.ordinal() is the animation corresponding to the orientation Orientation.dir
    void
    draw(Canvas canvas)
    Renders itself on specified canvas.
    boolean
    ???
    void
    Reset this animation by setting the current frame to the first of the sequence
    void
    setAnchor(Vector anchor)
    ???
    void
    setHeight(float height)
     
    void
    setSpeedFactor(int SPEED_FACTOR)
    Update the speed factor of this Animation.
    void
    setWidth(float width)
    ???
    void
     
    void
    update(float deltaTime)
    Simulates a single time step.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Animation

      public Animation(String name, int nbFrames, float width, float height, Positionable parent, int regionWidth, int regionHeight, Vector anchor, int frameDuration, boolean repeat)
    • Animation

      public Animation(String name, int nbFrames, float width, float height, Positionable parent, int regionWidth, int regionHeight, int frameDuration, boolean repeat)
    • Animation

      public Animation(int frameDuration, Sprite[] sprites, boolean repeat)
      Default Animation Constructor
      Parameters:
      frameDuration - (int): Duration of each frame (all frames have same duration)
      sprites - (Sprite...): Array of sprite in the correct sequence order. Not null
      repeat - (boolean): if the animation should be repeated after it is completed
    • Animation

      public Animation(int frameDuration, Sprite[] sprites)
      Repeated animation constructor
      Parameters:
      frameDuration - (int): Duration of each frame (all frames have same duration)
      sprites - (Sprite...): Array of sprite in the correct sequence order. Not null
  • Method Details

    • createAnimations

      public static Animation[] createAnimations(int animationDuration, Sprite[][] sprites, boolean repeat)
      Creates an array of 4 animations (one animation per orientation) the entry indexed by Orientation.dir.ordinal() is the animation corresponding to the orientation Orientation.dir
      Parameters:
      animationDuration - (int): the animation duration
      sprites - (Sprite[][]): sprites to be played by each animation sprites[Orientation.dir.ordinal()] is the set of sprites to be played by the animation indexed by Orientation.dir.ordinal()
      repeat - (boolean) : true if the animations must be repeated
      Returns:
      an array of 4 animations (one animation per orientation)
    • createAnimations

      public static Animation[] createAnimations(int animationDuration, Sprite[][] sprites)
      Creates an array of 4 animations (one animation per orientation) the entry indexed by Orientation.dir.ordinal() is the animation corresponding to the orientation Orientation.dir. The animations are repeated by default.
      Parameters:
      animationDuration - (int): the animation duration
      sprites - (Sprite[][]): sprites to be played by each animation sprites[Orientation.dir.ordinal()] is the set of sprites to be played by the animation indexed by Orientation.dir.ordinal()
      Returns:
      an array of 4 animations (one animation per orientation)
    • setSpeedFactor

      public void setSpeedFactor(int SPEED_FACTOR)
      Update the speed factor of this Animation. Can be done on the fly. Note the speed factor is given between 1 (original speed) and frameDuration (maximal speed) Hence we cannot slow down the animation !
      Parameters:
      SPEED_FACTOR - (int): new speed factor. Will be cropped between 1 and frameDuration
    • isCompleted

      public boolean isCompleted()
      ???
      Returns:
      ???
    • setAnchor

      public void setAnchor(Vector anchor)
      ???
      Parameters:
      anchor - ???
    • setWidth

      public void setWidth(float width)
      ???
      Parameters:
      width - ???
    • setHeight

      public void setHeight(float height)
    • reset

      public void reset()
      Reset this animation by setting the current frame to the first of the sequence
    • switchPause

      public void switchPause()
    • update

      public void update(float deltaTime)
      Description copied from interface: Updatable
      Simulates a single time step. Note: Need to be Override
      Specified by:
      update in interface Updatable
      Parameters:
      deltaTime - elapsed time since last update, in seconds, non-negative
    • draw

      public void draw(Canvas canvas)
      Description copied from interface: Graphics
      Renders itself on specified canvas.
      Specified by:
      draw in interface Graphics
      Parameters:
      canvas - target, not null