mgdk
Class MSprite

java.lang.Object
  |
  +--javax.microedition.lcdui.game.Layer
        |
        +--javax.microedition.lcdui.game.Sprite
              |
              +--mgdk.MSprite
Direct Known Subclasses:
M8Sprite

public class MSprite
extends javax.microedition.lcdui.game.Sprite

Extends Sprite, adding easier creation and better control over animation. Use new functions to create animations and activate one of them, after that you use Sprite functions to control it. Todo: Add delay in animations. Add individual delay to frames in animation. Add animation behavior (loop, bounce, hide?) Add animation ranges (startframe, endframe)

See Also:
Sprite

Field Summary
 int vx
          Velocity x.
 int vy
          Velocity y.
 
Fields inherited from class javax.microedition.lcdui.game.Sprite
TRANS_MIRROR, TRANS_MIRROR_ROT180, TRANS_MIRROR_ROT270, TRANS_MIRROR_ROT90, TRANS_NONE, TRANS_ROT180, TRANS_ROT270, TRANS_ROT90
 
Constructor Summary
MSprite(MSprite sprite)
          Creates this sprite as a copy of another MSprite.
MSprite(java.lang.String filename, int frameWidth, int frameHeight)
          Creates a sprite based on an image loaded from the specified filename.
 
Method Summary
 void activateAnimset(int num)
          Activates one of the sprites animationssets.
 void createAnimsets(int num)
          Creates the specified (num)ber of animation sets.
 MCollisionInfo detailedCollidesWith(MMap map, boolean pixel)
          Checks for collisions between the sprite and a map and gives detailed information about it.
 int getAnimsetNum()
          Returns the number of the active animset.
 void move()
          Moves the sprite using its velocity.
 void nextFrame()
           
 void setAnimDelay(int num, int[] delays)
           
 void setAnimset(int num, int[] sequence)
          Sets the framesequence of a animationset.
 void setVelocity(int vx, int vy)
          Set sprites velocity (speed & direction).
 void setX(int x)
          Conveniencemethod for changing a sprites horizontal position.
 void setY(int y)
          Conveniencemethod for changing a sprites vertical position.
 
Methods inherited from class javax.microedition.lcdui.game.Sprite
collidesWith, collidesWith, collidesWith, defineCollisionRectangle, defineReferencePixel, getFrame, getFrameSequenceLength, getRawFrameCount, getRefPixelX, getRefPixelY, paint, prevFrame, setFrame, setFrameSequence, setImage, setRefPixelPosition, setTransform
 
Methods inherited from class javax.microedition.lcdui.game.Layer
getHeight, getWidth, getX, getY, isVisible, move, setPosition, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vx

public int vx
Velocity x. To lazy to make it private


vy

public int vy
Velocity y. To lazy to make it private

Constructor Detail

MSprite

public MSprite(MSprite sprite)
Creates this sprite as a copy of another MSprite.

Parameters:
sprite - Sprite to clone.

MSprite

public MSprite(java.lang.String filename,
               int frameWidth,
               int frameHeight)
Creates a sprite based on an image loaded from the specified filename.

Method Detail

createAnimsets

public void createAnimsets(int num)
Creates the specified (num)ber of animation sets. Call this first when creating multiple animations for a frame. If you only need one animationset, use the standard Sprite functions. After calling this one, you use setAnimset to add each animationset.

Parameters:
num - number of animationsets to use.

setAnimset

public void setAnimset(int num,
                       int[] sequence)
Sets the framesequence of a animationset. Be sure to call createAnimsets before you call this one.

Parameters:
num - The number of the animset to set (change).
sequence - Framesequence to be stored.

setAnimDelay

public void setAnimDelay(int num,
                         int[] delays)

activateAnimset

public void activateAnimset(int num)
Activates one of the sprites animationssets. Use the standard Sprite functions to switch between frames in it.

Parameters:
num - The number of the animset to activate.

getAnimsetNum

public int getAnimsetNum()
Returns the number of the active animset.


nextFrame

public void nextFrame()
Overrides:
nextFrame in class javax.microedition.lcdui.game.Sprite

setVelocity

public void setVelocity(int vx,
                        int vy)
Set sprites velocity (speed & direction). Can be used for linear motion.

Parameters:
vx - horizontal velocity .
vy - vertical velocity.

move

public void move()
Moves the sprite using its velocity.


setX

public void setX(int x)
Conveniencemethod for changing a sprites horizontal position. Equal to calling Sprite.setPosition(x, Sprite.getY());

Parameters:
x - New x coordinate.

setY

public void setY(int y)
Conveniencemethod for changing a sprites vertical position.

Parameters:
y - New y coordinate.

detailedCollidesWith

public MCollisionInfo detailedCollidesWith(MMap map,
                                           boolean pixel)
Checks for collisions between the sprite and a map and gives detailed information about it. Only works as indented for sprites which are smaller than the cells in the map (or equal), otherwise entierly overlaped cells are ignored.

Parameters:
map - The map which contains tiles that the sprite might collide with.
See Also:
MCollisionInfo