jplay
Class Animation

java.lang.Object
  extended by jplay.GameObject
      extended by jplay.GameImage
          extended by jplay.Animation
Direct Known Subclasses:
Sprite

public class Animation
extends GameImage

Class responsible for animating a GameImage using pieces of the image, such as frames.


Field Summary
 
Fields inherited from class jplay.GameObject
height, width, x, y
 
Constructor Summary
Animation(java.lang.String fileName)
          Overloading of the constructor public Animation(String fileName, int totalFrames, boolean loop).
Animation(java.lang.String fileName, int totalFrames)
          Overloading of the constructor public Animation(String fileName, int totalFrames, boolean loop).
Animation(java.lang.String fileName, int totalFrames, boolean loop)
          The constructor creates a class object animation.
 
Method Summary
 void draw()
          Draws the animtion on escreen.
 int getCurrFrame()
          Returns the number of current frame.
 long getDuration(int frame)
          Return the time in which the frame is shown on screen.
 int getFinalFrame()
          Returns the number of final frame of the sequence of frames.
 int getInitialFrame()
          Returns the number of initial frame.
 long getTotalDuration()
          Returns the sum of all time frames.
 void hide()
          This method is responsible for not allowing to drawn the animation on screen.
 boolean isLooping()
          This method tells whether the animation is looped.
 boolean isPlaying()
          Returns true if the animation is being executed, false otherwise.
 void pause()
          Method responsible for pausing the animation.
 void play()
          Method responsible for starting the execution of the animation.
 void setCurrFrame(int frame)
          Sets the current frame that will be drawn.
 void setDuration(int frame, long time)
          Set up the time which the frame will be shown on screen.
 void setFinalFrame(int frame)
          Sets the final frame of the sequence of frames.
 void setInitialFrame(int frame)
          Sets the initial frame of the sequence of frames.
 void setLoop(boolean value)
          Method responsible for informing the class that the animation will not be run indefinitely.
 void setSequence(int initialFrame, int finalFrame)
          Set the initial and final frame in the sequence of animation.
 void setSequence(int initialFrame, int finalFrame, boolean loop)
          Set the initial and final frame in the sequence of animation.
 void setSequenceTime(int initialFrame, int finalFrame, boolean loop, long time)
          Set the initial and final frame in the sequence of animation, the runtime and if it will run indefinitely.
 void setSequenceTime(int initialFrame, int finalFrame, long time)
          Set the initial and final frame in the sequence of animation and the runtime.
 void setTotalDuration(long time)
           
 void stop()
          Stops execution and puts the initial frame as the current frame.
 void unhide()
          Method responsible for allowing the animation to draw on the screen.
 void update()
          Method responsible for performing the change of frames.
 
Methods inherited from class jplay.GameImage
loadImage
 
Methods inherited from class jplay.GameObject
collided
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Animation

public Animation(java.lang.String fileName,
                 int totalFrames,
                 boolean loop)
The constructor creates a class object animation. The sequence set up to start in the frame one and goes until the lastFrame that is equal to totalFrames. For example: setSequence(0, totalFrames). 0 = initial frame. lastFrame = totalFrames.

Parameters:
fileName - Name and image path.
totalFrames - Number of frames that form the image.
It - says if the animation is performed repeatedly. If the value is true when the last frame is shown the next frame will be the first. However, if the value is false when the last frame is shown the animation will remain showing the last frame indefinitely.

Animation

public Animation(java.lang.String fileName,
                 int totalFrames)
Overloading of the constructor public Animation(String fileName, int totalFrames, boolean loop). The parameter 'boolean loop' has the value true.


Animation

public Animation(java.lang.String fileName)
Overloading of the constructor public Animation(String fileName, int totalFrames, boolean loop). The parameter 'boolean loop' has the value true. The parameter 'int totalFrames' is equal to 1.

Method Detail

setDuration

public void setDuration(int frame,
                        long time)
Set up the time which the frame will be shown on screen.

Parameters:
frame - Number of the frame
time - Milliseconds time which the frame will be shown on screen.

getDuration

public long getDuration(int frame)
Return the time in which the frame is shown on screen.

Parameters:
frame - number of frame
Returns:
long - the time in milliseconds

setSequence

public void setSequence(int initialFrame,
                        int finalFrame)
Set the initial and final frame in the sequence of animation. The sequence will run indefinitely.

Parameters:
initialFrame -
finalFrame -

setSequence

public void setSequence(int initialFrame,
                        int finalFrame,
                        boolean loop)
Set the initial and final frame in the sequence of animation. And if the animation will run indefinitely.

Parameters:
initialFrame -
finalFrame -
loop -

setSequenceTime

public void setSequenceTime(int initialFrame,
                            int finalFrame,
                            long time)
Set the initial and final frame in the sequence of animation and the runtime.

Parameters:
initialFrame -
finalFrame -
time -

setSequenceTime

public void setSequenceTime(int initialFrame,
                            int finalFrame,
                            boolean loop,
                            long time)
Set the initial and final frame in the sequence of animation, the runtime and if it will run indefinitely.

Parameters:
initialFrame -
finalFrame -
time -
loop - True for indefinitely, false otherwise.

isLooping

public boolean isLooping()
This method tells whether the animation is looped.

Returns:
boolean

setTotalDuration

public void setTotalDuration(long time)

getTotalDuration

public long getTotalDuration()
Returns the sum of all time frames.

Returns:
long

update

public void update()
Method responsible for performing the change of frames.


stop

public void stop()
Stops execution and puts the initial frame as the current frame.


play

public void play()
Method responsible for starting the execution of the animation.


pause

public void pause()
Method responsible for pausing the animation.


setInitialFrame

public void setInitialFrame(int frame)
Sets the initial frame of the sequence of frames.

Parameters:
frame - number of frame

getInitialFrame

public int getInitialFrame()
Returns the number of initial frame.

Returns:
int

setFinalFrame

public void setFinalFrame(int frame)
Sets the final frame of the sequence of frames.

Parameters:
frame - number of frame.

getFinalFrame

public int getFinalFrame()
Returns the number of final frame of the sequence of frames.

Returns:
int

setCurrFrame

public void setCurrFrame(int frame)
Sets the current frame that will be drawn.

Parameters:
frame - number of frame.

getCurrFrame

public int getCurrFrame()
Returns the number of current frame.

Returns:
int

isPlaying

public boolean isPlaying()
Returns true if the animation is being executed, false otherwise.

Returns:
boolean

hide

public void hide()
This method is responsible for not allowing to drawn the animation on screen.


unhide

public void unhide()
Method responsible for allowing the animation to draw on the screen.


setLoop

public void setLoop(boolean value)
Method responsible for informing the class that the animation will not be run indefinitely. True to run indefinitely, false otherwise.


draw

public void draw()
Draws the animtion on escreen.

Overrides:
draw in class GameImage