game.graphics.sprite
Class CAnimatedSprite

java.lang.Object
  extended by game.physics.CStaticShape
      extended by game.physics.CDynamicShape
          extended by game.graphics.sprite.CAnimatedSprite
All Implemented Interfaces:
ICriticalObject, IGraphicObject

public class CAnimatedSprite
extends CDynamicShape
implements IGraphicObject, ICriticalObject

This class implements time indexed animated sprites. Animation can be reversed at any time.

Author:
seb

Field Summary
private  java.awt.image.BufferedImage[] m_aSprites
           
private  float[] m_aTimeIntervals
           
private  boolean m_bReverseAnimation
           
private  int m_index
           
private  boolean m_isCycling
           
private  float m_t
           
 
Fields inherited from class game.physics.CDynamicShape
G, m_bApplyGravity, m_bBouceOnGameRect, m_v
 
Fields inherited from class game.physics.CStaticShape
m_box, m_gameDisplay, m_isHidden
 
Fields inherited from interface game.graphics.ICriticalObject
CRITICAL_VALUE
 
Constructor Summary
CAnimatedSprite(IGameDisplay gameRect, CBoundingBox box, CVector2D velocity, java.awt.Image imgSprites, float fFrameTime)
          Fixed frame time version of the above.
CAnimatedSprite(IGameDisplay gameRect, CBoundingBox box, CVector2D velocity, java.awt.Image imgSprites, float[] aFrameTimes)
           
 
Method Summary
 void animate(float dt)
          Animates the sprite.
protected  void bounceOnGameRect()
          Same as inherited function.
 void draw(java.awt.Graphics g)
          Simply draws the current image.
private  float[] generateTimeIntervals(float fFrameTime)
          Generates an array of equal time intervals.
private  void initTimeIntervals(float[] aTimeIntervals)
           
 boolean isCritical()
           
private  void splitSprites(java.awt.Image img)
          Takes an Image and splits it in a sprite array.
 
Methods inherited from class game.physics.CDynamicShape
cycle, getVelocity
 
Methods inherited from class game.physics.CStaticShape
drawBox, getCenter, hide, intersect, isHidden, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_aSprites

private java.awt.image.BufferedImage[] m_aSprites

m_aTimeIntervals

private float[] m_aTimeIntervals

m_index

private int m_index

m_t

private float m_t

m_isCycling

private final boolean m_isCycling
See Also:
Constant Field Values

m_bReverseAnimation

private boolean m_bReverseAnimation
Constructor Detail

CAnimatedSprite

public CAnimatedSprite(IGameDisplay gameRect,
                       CBoundingBox box,
                       CVector2D velocity,
                       java.awt.Image imgSprites,
                       float[] aFrameTimes)
Parameters:
gameRect - : the rectangle the sprite will evolve in
box - : the sprite's bounding box (can be different than image size)
velocity - : sprite's initial velocity
imgSprites - : the sprite's image array
aFrameTimes - : the frame time indexes array

CAnimatedSprite

public CAnimatedSprite(IGameDisplay gameRect,
                       CBoundingBox box,
                       CVector2D velocity,
                       java.awt.Image imgSprites,
                       float fFrameTime)
Fixed frame time version of the above.

Parameters:
fFrameTime - : the constant frame time.
Method Detail

splitSprites

private final void splitSprites(java.awt.Image img)
Takes an Image and splits it in a sprite array. Uses a CImageProcessor to split the Image.

Parameters:
img - the image containing the sprite animation
See Also:
CImageProcessor

generateTimeIntervals

private final float[] generateTimeIntervals(float fFrameTime)
Generates an array of equal time intervals.

Parameters:
fFrameTime - the fixed time interval
Returns:
an array of fixed time intervals

initTimeIntervals

private final void initTimeIntervals(float[] aTimeIntervals)

animate

public final void animate(float dt)
Animates the sprite. Contains the major part of the magic.

Specified by:
animate in interface IGraphicObject
Overrides:
animate in class CDynamicShape
Parameters:
dt - : the amount of time to advance of.

draw

public void draw(java.awt.Graphics g)
Simply draws the current image.

Specified by:
draw in interface IGraphicObject

bounceOnGameRect

protected void bounceOnGameRect()
Same as inherited function. Except that it reverses the animation for demonstration purpose.

Overrides:
bounceOnGameRect in class CDynamicShape

isCritical

public boolean isCritical()
Specified by:
isCritical in interface ICriticalObject