Game Development Reference
In-Depth Information
3.4 Animations
Animation is the process of creating a continuous motion and shape change. Animated im-
ages are displayed in a rapid succession, usually 24, 25, or 30 frames per second [5] .
As shown in figure 3.2 and 3.3, in the project Raccoon Rob, there're a few sprite sheets
that contain subsets - frames with identical sizes. Here we'll introduce an important method
cutBitmap(), which is designed to traverse all frames in a sprite sheet to cut them out for
animations. This method is the base of the animation methods in section 3.1, and you can
find its full implementation in the class BitmapManager .
//Subsets the source bitmap to frames with the specified size w x h,
//stores the result in a bitmap array.
//Returns a 2D array of int[][] containing subset IDs
//Parameters:
// source - the specified bitmap to be subset
// result - a bitmap array that stores the frames
// imgid - the image id of source
// px - offset x coordinate
// py - offset y coordinate
// crows - the number of rows to be returned
// ccols - the number of cols to be returned
// rows - the number of rows
// cols - the number of cols
// w - the width of the frame
// h - the height of the frame
public static int [][] cutBitmap(Bitmap source, Bitmap [] result, int imgid,
int px, int py, int crows, int ccols,
int rows, int cols, int w, int h) {
int [][] baseList = new int [crows][ccols];
for ( int i=0;i<rows;i++){
for ( int j=0;j<cols;j++){
result[imgid+i*cols+j] = Bitmap.createBitmap(
source, px+j*w, py+i*h, w, h);
}
}
for ( int i=0;i<crows;i++){
for ( int j=0;j<ccols;j++){
baseList[i][j] = imgid+i*ccols+j;
Search WWH ::




Custom Search