com.alienfactory.javamappy
Class AnimBlock

java.lang.Object
  extended by com.alienfactory.javamappy.AnimBlock

public class AnimBlock
extends java.lang.Object

AnimBlock represents a sequence of frames (images) that will be played out according to the animation type and a speed dictated by the frame delay.

The animation type names and sequence events are true to the Mappy code. (I hope!)

Author:
Steve Eynon

Field Summary
static int AN_LOOPF
          Loop Forward.
static int AN_LOOPR
          Loop Reverse.
static int AN_NONE
          Do Not Animate.
static int AN_ONCE
          Animate Once.
static int AN_ONCEH
          Animate Once & Halt.
static int AN_ONCES
          Animate Once Finished.
static int AN_PPFF
          Ping Ping Forward - Outward Leg.
static int AN_PPFR
          Ping Ping Forward - Return Leg.
static int AN_PPRF
          Ping Ping Reverse - Outward Leg.
static int AN_PPRR
          Ping Ping Reverse - Return Leg.
 
Constructor Summary
AnimBlock()
           
 
Method Summary
 int getCurrentFrame()
          Returns the current frame (image index).
 int getCurrentFrameIndex()
          Returns the current frame index.
 int getDelay()
          The delay is the number of times updateAnimation() needs to be called before the currentFrameIndex changes.
 int getDelayCountdown()
          Returns the number of times updateAnimation() has to be called before the current frame is changed to the next in sequence.
 int[] getFrames()
          Returns an array of frames (image indexs) that represent the animation sequence.
 int getType()
          The type dictates how the animation sequence will be played out.
 int getUserData()
          Returns any user defined data.
 void setCurrentFrameIndex(int currentFrameIndex)
          Sets the current frame index.
 void setDelay(int delay)
          The delay is the number of times updateAnimation() needs to be called before the currentFrameIndex changes.
 void setDelayCountdown(int count)
          Sets the number of times updateAnimation() has to be called before the current frame is changed to the next in sequence.
 void setFrames(int[] frames)
          Sets the frames (image indexs) that represent the animation sequence.
 void setType(int type)
          The type dictates how the animation sequence will be played out.
 void setUserData(int userData)
          Sets any user defined data.
 void updateAnimation()
          Counts down the delay and updates the current frame to the next in the animation sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AN_NONE

public static final int AN_NONE
Do Not Animate. An AnimBlock type.

By setting the animation type to AN_NONE the current frame will stay as it is.

Given 5 frames and no delay, upon successive calls to updateAnimation(), getCurrentFrameIndex() would return:

[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . ]

Has a constant value of 0.

See Also:
getType(), setType(int), Constant Field Values

AN_LOOPF

public static final int AN_LOOPF
Loop Forward. An AnimBlock type.

Given 5 frames and no delay, upon successive calls to updateAnimation(), getCurrentFrameIndex() would return:

[ 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 3 . . . ]

Has a constant value of 1.

See Also:
getType(), setType(int), Constant Field Values

AN_LOOPR

public static final int AN_LOOPR
Loop Reverse. An AnimBlock type.

Given 5 frames and no delay, upon successive calls to updateAnimation(), getCurrentFrameIndex() would return:

[ 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 . . . ]

Has a constant value of 2.

See Also:
getType(), setType(int), Constant Field Values

AN_ONCE

public static final int AN_ONCE
Animate Once. An AnimBlock type.

After the animation sequence finishes the current frame will reset to the first frame and the animation type will change to AN_ONCES.

Given 5 frames and no delay, upon successive calls to updateAnimation(), getCurrentFrameIndex() would return:

[ 0 1 2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . ]

Has a constant value of 3.

See Also:
getType(), setType(int), Constant Field Values

AN_ONCES

public static final int AN_ONCES
Animate Once Finished. An AnimBlock type.

The animation type is automatically set to this after the AN_ONCE sequence has finished. AN_ONCES behaves the same as AN_ONCES.

Has a constant value of 9.

See Also:
getType(), setType(int), Constant Field Values

AN_ONCEH

public static final int AN_ONCEH
Animate Once & Halt. An AnimBlock type.

After the animation sequence finishes the current frame sticks to the last frame. Unlike AN_ONCE the animation type does not change.

Given 5 frames and no delay, upon successive calls to updateAnimation(), getCurrentFrameIndex() would return:

[ 0 1 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 . . . ]

Has a constant value of 4.

See Also:
getType(), setType(int), Constant Field Values

AN_PPFF

public static final int AN_PPFF
Ping Ping Forward - Outward Leg. An AnimBlock type.

When the animation sequence reaches the end of the forward 'ping' the animation type changes to AN_PPFR and the sequence begins it's return journey.

It could be argued that there is no difference between AN_PPFF and AN_PPRR.

Given 5 frames and no delay, upon successive calls to updateAnimation(), getCurrentFrameIndex() would return:

[ 0 1 2 3 4 3 2 1 0 1 2 3 4 3 2 1 0 1 . . . ]

Has a constant value of 5.

See Also:
getType(), setType(int), Constant Field Values

AN_PPFR

public static final int AN_PPFR
Ping Ping Forward - Return Leg. An AnimBlock type.

When the animation sequence reaches the end of the forward 'pong' the animation type changes to AN_PPFF and the sequence starts all over again.

It could be argued that there is no difference between AN_PPFR and AN_PPRF.

Given 5 frames and no delay, upon successive calls to updateAnimation(), getCurrentFrameIndex() would return:

[ 4 3 2 1 0 1 2 3 4 3 2 1 0 1 2 3 4 3 . . . ]

Has a constant value of 6.

See Also:
getType(), setType(int), Constant Field Values

AN_PPRF

public static final int AN_PPRF
Ping Ping Reverse - Outward Leg. An AnimBlock type.

When the animation sequence reaches the end of the forward 'ping' the animation type changes to AN_PPRR and the sequence begins it's return journey.

It could be argued that there is no difference between AN_PPRF and AN_PPFR.

Given 5 frames and no delay, upon successive calls to updateAnimation(), getCurrentFrameIndex() would return:

[ 4 3 2 1 0 1 2 3 4 3 2 1 0 1 2 3 4 3 . . . ]

Has a constant value of 7.

See Also:
getType(), setType(int), Constant Field Values

AN_PPRR

public static final int AN_PPRR
Ping Ping Reverse - Return Leg. An AnimBlock type.

When the animation sequence reaches the end of the forward 'pong' the animation type changes to AN_PPRR and the sequence starts all over again.

It could be argued that there is no difference between AN_PPRR and AN_PPFF.

Given 5 frames and no delay, upon successive calls to updateAnimation(), getCurrentFrameIndex() would return:

[ 0 1 2 3 4 3 2 1 0 1 2 3 4 3 2 1 0 1 . . . ]

Has a constant value of 8.

See Also:
getType(), setType(int), Constant Field Values
Constructor Detail

AnimBlock

public AnimBlock()
Method Detail

getType

public int getType()
The type dictates how the animation sequence will be played out. Will it play once and stop or loop forever?

Returns:
the animation type

setType

public void setType(int type)
             throws java.lang.IllegalArgumentException
The type dictates how the animation sequence will be played out. Will it play once and stop or loop forever?

Setting the animation type does not reset / any other values.

Parameters:
type - the new animation type
Throws:
java.lang.IllegalArgumentException - if type is out of bounds

getDelay

public int getDelay()
The delay is the number of times updateAnimation() needs to be called before the currentFrameIndex changes. In effect this controls the speed of the animation.

Returns:
the frame delay
See Also:
getDelayCountdown(), setDelayCountdown(int)

setDelay

public void setDelay(int delay)
              throws java.lang.IllegalArgumentException
The delay is the number of times updateAnimation() needs to be called before the currentFrameIndex changes. In effect this controls the speed of the animation.

Parameters:
delay - the new frame delay
Throws:
java.lang.IllegalArgumentException - if delay is less than zero
See Also:
getDelayCountdown(), setDelayCountdown(int)

getDelayCountdown

public int getDelayCountdown()
Returns the number of times updateAnimation() has to be called before the current frame is changed to the next in sequence. If getCount() == 0 the current frame will change on the next call to updateAnimation() and count will reset to delay.

Returns:
the countdown to a frame change
See Also:
getDelay()

setDelayCountdown

public void setDelayCountdown(int count)
                       throws java.lang.IllegalArgumentException
Sets the number of times updateAnimation() has to be called before the current frame is changed to the next in sequence.

Throws:
java.lang.IllegalArgumentException - if count is less than zero

getCurrentFrameIndex

public int getCurrentFrameIndex()
Returns the current frame index.


setCurrentFrameIndex

public void setCurrentFrameIndex(int currentFrameIndex)
Sets the current frame index.


getCurrentFrame

public int getCurrentFrame()
Returns the current frame (image index). If this anim block has no frames then 0 is returned.

Returns:
the current image index

getFrames

public int[] getFrames()
Returns an array of frames (image indexs) that represent the animation sequence.


setFrames

public void setFrames(int[] frames)
               throws java.lang.IllegalArgumentException
Sets the frames (image indexs) that represent the animation sequence.

Throws:
java.lang.IllegalArgumentException - is frames is null

getUserData

public int getUserData()
Returns any user defined data.


setUserData

public void setUserData(int userData)
Sets any user defined data.


updateAnimation

public void updateAnimation()
Counts down the delay and updates the current frame to the next in the animation sequence.



Copyright © 2001-2009 Alien-Factory Ltd. All Rights Reserved.