Game Development Reference
In-Depth Information
3.1 Sprite Class
A sprite is a stand-alone 2 or 3-dimensional animated character or object. The class Sprite
encapsulates all members and methods of sprites. It's the base of other subclasses such as
hero, monster, NPC, etc.
Building the Constructor
The Constructor creates a sprite instance based on the specified typeID and position of
sprite.
//Constructor: creates a sprite instance based on
//the specified TypeID and position of sprite
//Parameters:
// type - the TypeID of the specified sprite. 0-hero, 1-monster1, 2-monster2
// col - the column# of the position
// row - the row# of the position
public Sprite( int type, int col, int row){
this .type = type;
//if(type==0) this.life = MAX_LIFE;
this .col = col;
this .row = row;
this .x = col * TILE_SIZE;
this .y = row * TILE_SIZE+TILE_SIZE-SPRITE_HEIGHT;
st = new SpriteThread( this );
}
Making Animation Segments
An animation segment is an ArrayList that stores the image IDs of the specified frames. The
snippet below shows how the animation segments are made and how the continuous frame
sequence is altered during an animation:
//Adds the specified object (int array of ImageID) into
//the Animation ArrayList through a for loop.
public void makeAnimation( int [][] imgId){
for ( int [] imgIDs:imgId){
addAnimationSegment(imgIDs);
}
}
Search WWH ::




Custom Search