Game Development Reference
In-Depth Information
Let's take a look at the code for the class in its entirety first:
package com.efg.framework{
import flash.display.BitmapData;import flash.geom.*;
/**
* ...
* @author Jeff Fulton
*/
public class TileSheet {
public var sourceBitmapData:BitmapData;
public var width:int;
public var height:int;
public var tileWidth:int;
public var tileHeight:int;
public var tilesPerRow:int;
public function TileSheet(sourceBitmapData:BitmapData,tileWidth:int,
tileHeight:int ) {
this.sourceBitmapData = sourceBitmapData;
width = sourceBitmapData.width;
height = sourceBitmapData.height;
this.tileHeight = tileHeight;
this.tileWidth = tileWidth;
tilesPerRow = int(width / this.tileWidth);
}
}
}
Understanding the attributes of a TileSheet
To use a tile sheet as a source for game graphics, we need to define and have access to several
variables. The constructor only receives three pieces of information:
(sourceBitmapData:BitmapData,tilewidth:int, tileheight:int)
private var sourceBitmapData:BitmapData;
In the constructor you will find this line of code:
this.sourceBitmapData=sourceBitmapdata;
The sourceBitmapData represents the actual PNG sheet of tiles that will be the source of out
blitting operations. This variable holds a reference to the BitmapData instance that is passed into
the constructor. For our game, we have a sheet that is 256
128. That is good for eight columns
32
32 tiles and four rows. The next two variables represent the actual width and height of the
sheet.
private var width:int;
private var height:int;
In the constructor, these are set based on the width and height of the passed in BitmapData .
width = sourceBitmapData.width;
height = sourceBitmapData.height;
Search WWH ::




Custom Search