GF4J 0.9.4 Beta

gameframe.graphics
Class AnimBitmap

java.lang.Object
  |
  +--gameframe.graphics.AnimBitmap
All Implemented Interfaces:
Bitmap

public class AnimBitmap
extends java.lang.Object
implements Bitmap

Implementation of an animated bitmap. Has multiple animation modes like ping-pong, one shot or looping. It implements the Bitmap interface and adds methods for handling the animation.

Since:
GameFrame for Java 0.9.4
Version:
GameFrame for Java 0.9.4
Author:
Pasi Keränen 04. Apr 2000

Field Summary
static int DIR_FORWARD
          Enumerated direction of the animation.
static int DIR_REVERSE
          Enumerated direction of the animation.
static int DIR_STOPPED
          Enumerated direction of the animation.
static int MODE_LOOP
          Enumerated animation mode.
static int MODE_ONCE
          Enumerated animation mode.
static int MODE_PING_PONG
          Enumerated animation mode.
 
Constructor Summary
AnimBitmap(Bitmap[] bitmaps)
          Constructs an animated bitmap from the series of Bitmap objects given.
AnimBitmap(Bitmap tiledBitmap, int cellWidth, int cellHeight)
          Constructs an animated bitmap from the given Bitmap that contains the animation cells.
 
Method Summary
 void advanceFrames(float flNumFrames)
          Advances the animation the number of frames given to the direction it is configured to go.
 void advanceFrames(int iNumFrames)
          Deprecated. Use advanceFrames( float ) instead of the advanceFrames( int ) version.
 void blitTo(DrawableBitmap bitmap, int x, int y)
          Draws the currently shown bitmap to the given drawable bitmap at the given location.
 void blitTo(int x, int y)
          Draws the currently shown bitmap to the graphics engine that loaded it at the given location.
 void finalize()
          Frees all the resources that are used by the animated bitmap implementation.
 Bitmap[] getBitmapClones()
          Returns a copy of the used bitmaps in the animation.
 Bitmap getClone(BitmapEffect effect)
          Returns an effect processed copy of the currently shown bitmap.
 int getDirection()
          Returns the animation direction of this animated bitmap.
 int getHeight()
          Returns the height of the currently shown bitmap.
 int getMode()
          Returns the animation mode of this animated bitmap.
 Bitmap getSubBitmap(int srcX, int srcY, int srcWidth, int srcHeight)
          Returns the subbitmap of the current animation frame.
 Bitmap getSubBitmapClone(int srcX, int srcY, int srcWidth, int srcHeight)
          Returns the subbitmap clone of the current animation frame.
 int getWidth()
          Returns the width of the currently shown bitmap.
 void nextFrame()
          Advances the animation one frame to the direction it is configured to go.
 void playForward()
          Tells the animation to play forward (from first animation cell to the last).
 void playReverse()
          Tells the animation to play backwards (from last animation cell to the first).
 void setMode(int eMode)
          Sets the animation mode of this animated bitmap.
 void stop()
          Stops the animation.
 void strecthTo(DrawableBitmap bitmap, int x, int y, int width, int height)
          Draws the currently shown bitmap to the given drawable bitmap at the given location at the given size.
 void strecthTo(int x, int y, int width, int height)
          Draws the currently shown bitmap to the graphics engine that loaded it at the given location and at the given size.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_LOOP

public static final int MODE_LOOP
Enumerated animation mode. Plays the animation over and over again starting from the first and looping back to first when it reaches the last animation cell.

MODE_ONCE

public static final int MODE_ONCE
Enumerated animation mode. Plays the animation once and stops at the last animation cell.

MODE_PING_PONG

public static final int MODE_PING_PONG
Enumerated animation mode. Plays the animation once from first animation cell to the last and then reverses the direction and plays the animation from last to first and reverses the direction again.

DIR_REVERSE

public static final int DIR_REVERSE
Enumerated direction of the animation. Reverse playing sequence.

DIR_STOPPED

public static final int DIR_STOPPED
Enumerated direction of the animation. Stopped sequence.

DIR_FORWARD

public static final int DIR_FORWARD
Enumerated direction of the animation. Forward playing sequence.
Constructor Detail

AnimBitmap

public AnimBitmap(Bitmap[] bitmaps)
           throws GameFrameException
Constructs an animated bitmap from the series of Bitmap objects given.
Parameters:
bitmaps - The array of bitmaps to use.
Throws:
GameFrameException - when something goes wrong. Note: In this case the animated bitmap is not initialized and is not usable.

AnimBitmap

public AnimBitmap(Bitmap tiledBitmap,
                  int cellWidth,
                  int cellHeight)
           throws GameFrameException
Constructs an animated bitmap from the given Bitmap that contains the animation cells. Initially gets the subbitmaps from the given bitmap object and uses those subbitmaps to create the animation.
Parameters:
tiledBitmap - The bitmap containing the animation cells to use.
cellWidth - The width of one animation cell in the tiled bitmap.
cellHeight - The height of one animation cell in the tiled bitmap.
Throws:
GameFrameException - when something goes wrong. Note: In this case the animated bitmap is not initialized and is not usable.
Method Detail

setMode

public void setMode(int eMode)
Sets the animation mode of this animated bitmap.
Parameters:
eMode - An enumerated value of MODE_xxx type.

getMode

public int getMode()
Returns the animation mode of this animated bitmap.
Returns:
An enumerated value of MODE_xxx type.

getBitmapClones

public Bitmap[] getBitmapClones()
                         throws GameFrameException
Returns a copy of the used bitmaps in the animation.
Returns:
Copy of used bitmaps.
Throws:
GameFrameException - thrown if cloning isn't successfull.

stop

public void stop()
Stops the animation. Even if the nextFrame() or advanceFrame() methods are called the animation doesn't advance.

playForward

public void playForward()
Tells the animation to play forward (from first animation cell to the last). Note: In ping-pong mode this method has a limited meaning as ping- pong mode changes the direction of the animation constantly.

playReverse

public void playReverse()
Tells the animation to play backwards (from last animation cell to the first). Note: In ping-pong mode this method has a limited meaning as ping- pong mode changes the direction of the animation constantly.

getDirection

public int getDirection()
Returns the animation direction of this animated bitmap.
Returns:
An enumerated value of DIR_xxx type.

nextFrame

public void nextFrame()
Advances the animation one frame to the direction it is configured to go.

advanceFrames

public void advanceFrames(int iNumFrames)
Deprecated. Use advanceFrames( float ) instead of the advanceFrames( int ) version.

Advances the animation the number of frames given to the direction it is configured to go. You should use the advanceFrames( float ) method instead of this method as this method simply casts the given integer to a float in invokes that version of the method.
Parameters:
iNumFrames - Positive number of frames to advance.
See Also:
advanceFrames(float)

advanceFrames

public void advanceFrames(float flNumFrames)
Advances the animation the number of frames given to the direction it is configured to go. The frame number is a floating point number so that the animation can be advanced with e.g. 0.5 or 0.2 frames if needed
Parameters:
flNumFrames - Positive number of frames to advance.

blitTo

public void blitTo(int x,
                   int y)
Draws the currently shown bitmap to the graphics engine that loaded it at the given location. The location can be outside of the visible screen area in which case the currently shown bitmap is clipped accordingly. This method is fast and is usable during the game execution.
Specified by:
blitTo in interface Bitmap
Parameters:
x - The x-coordinate of the location where the image is drawn to.
y - The y-coordinate of the location where the image is drawn to.
Since:
GameFrame for Java 0.9

strecthTo

public void strecthTo(int x,
                      int y,
                      int width,
                      int height)
Draws the currently shown bitmap to the graphics engine that loaded it at the given location and at the given size. If currently shown bitmap is larger or smaller than the destination size the currently shown bitmap will automatically be scaled. Note: This method is usually a bit slow, so it's use is not preferred during interactive periods in game execution.
Specified by:
strecthTo in interface Bitmap
Parameters:
x - The x-coordinate of the location where the image is drawn to.
y - The y-coordinate of the location where the image is drawn to.
width - The with that is used when drawing the image.
height - The height that is used when drawing the image.
Since:
GameFrame for Java 0.9

blitTo

public void blitTo(DrawableBitmap bitmap,
                   int x,
                   int y)
Draws the currently shown bitmap to the given drawable bitmap at the given location. The location can be outside of the visible screen area in which case the bitmap is clipped accordingly. This method is fast and is usable during the game execution.
Specified by:
blitTo in interface Bitmap
Parameters:
bitmap - The bitmap that will be drawn to.
x - The x-coordinate of the location where the image is drawn to.
y - The y-coordinate of the location where the image is drawn to.
Since:
GameFrame for Java 0.9

strecthTo

public void strecthTo(DrawableBitmap bitmap,
                      int x,
                      int y,
                      int width,
                      int height)
Draws the currently shown bitmap to the given drawable bitmap at the given location at the given size. If currently shown bitmap is larger or smaller than the destination size the currently shown bitmap will automatically be scaled. Note: This method is usually quite slow, so it's use is not preferred during interactive periods in game execution.
Specified by:
strecthTo in interface Bitmap
Parameters:
bitmap - The bitmap that will be drawn to.
x - The x-coordinate of the location where the image is drawn to.
y - The y-coordinate of the location where the image is drawn to.
width - The with that is used when drawing the image.
height - The height that is used when drawing the image.
Since:
GameFrame for Java 0.9

getWidth

public int getWidth()
Returns the width of the currently shown bitmap. This method is fast and is usable during the game execution.
Specified by:
getWidth in interface Bitmap
Returns:
Width of the currently shown bitmap if available.
Since:
GameFrame for Java 0.9.3

getHeight

public int getHeight()
Returns the height of the currently shown bitmap. This method is fast and is usable during the game execution.
Specified by:
getHeight in interface Bitmap
Returns:
Height of the currently shown bitmap if available.
Since:
GameFrame for Java 0.9.3
See Also:
Bitmap.getHeight()

getClone

public Bitmap getClone(BitmapEffect effect)
                throws GameFrameException

Returns an effect processed copy of the currently shown bitmap. This operation copies the actual bitmap data to a new memory location in a processed form and thus consumes memory.

Usually used to save graphics drawing time on game graphics as one can generate an animation sequence on the fly using gradual effects.

Specified by:
getClone in interface Bitmap
Parameters:
effect - The bitmap effect to be applied to the clone bitmap, or null if none are to be applied.
Returns:
An effect processed clone of the currently shown bitmap.
Throws:
GameFrameException - thrown if any errors occur.
See Also:
Bitmap.getHeight()

getSubBitmapClone

public Bitmap getSubBitmapClone(int srcX,
                                int srcY,
                                int srcWidth,
                                int srcHeight)
                         throws GameFrameException
Returns the subbitmap clone of the current animation frame. Works as the getSubBitmapClone() in Bitmap.
Specified by:
getSubBitmapClone in interface Bitmap
Parameters:
srcX - The leftmost coordinate of the currently shown bitmap to be returned as a new bitmap.
srcY - The topmost coordinate of the currently shown bitmap to be returned as a new bitmap.
srcWidth - The width of the currently shown bitmap to be returned as a new bitmap.
srcHeight - The height of the currently shown bitmap to be returned as a new bitmap.
Returns:
A new bitmap representing the requested part of the original bitmap.
Throws:
GameFrameException - Thrown if clone sub-bitmap creation is not successfull.
See Also:
Bitmap.getSubBitmapClone(int, int, int, int)

getSubBitmap

public Bitmap getSubBitmap(int srcX,
                           int srcY,
                           int srcWidth,
                           int srcHeight)
                    throws GameFrameException
Returns the subbitmap of the current animation frame. Works as the getSubBitmap() in Bitmap.
Specified by:
getSubBitmap in interface Bitmap
Parameters:
srcX - The leftmost coordinate of the currently shown bitmap to be returned as a new bitmap.
srcY - The topmost coordinate of the currently shown bitmap to be returned as a new bitmap.
srcWidth - The width of the currently shown bitmap to be returned as a new bitmap.
srcHeight - The height of the currently shown bitmap to be returned as a new bitmap.
Returns:
A new bitmap representing the requested part of the original bitmap.
Throws:
GameFrameException - Thrown if sub-bitmap creation is not successfull.
See Also:
Bitmap.getSubBitmap(int, int, int, int)

finalize

public void finalize()
Frees all the resources that are used by the animated bitmap implementation. This method is quite slow to execute and should preferrably be called upon exiting the game or between level changes etc.
Specified by:
finalize in interface Bitmap

GF4J 0.9.4 Beta