Game Development Reference
In-Depth Information
Parameters
sourceBitmapData:BitmapData The input bitmap image from which to copy
pixels. The source image can be a different BitmapData instance, or it can refer to
the current BitmapData instance.
sourceRect:Rectangle A rectangle that defines the area of the source image
to use as input.
destPoint:Point The destination point that represents the upper-left corner of
the rectangular area where the new pixels are placed.
alphaBitmapData:BitmapData ( default = null) A secondary, alpha
BitmapData object source.
alphaPoint:Point ( default = null) The point in the alpha BitmapData
object source that corresponds to the upper-left corner of the sourceRect parameter.
mergeAlpha:Boolean ( default = false) To use the alpha channel, set the
value to true. To copy pixels with no alpha channel, set the value to false.
Let's examine the cut method in the PieceCutter class. The above copyPixels is
used in the following way:
pd.copyPixels(bmd,
rect,
new Point(0, 0),
mask.bmd,
new Point(0, 0),
true);
Here bmd is the puzzle image bitmapdata, rect represents the part of the image for
which the piece is being created and the mask.bmd is the shape.
The rectangle ( rect ) is not as straightforward to determine for each as one would
expect. Depending on the shape, we need to account for an offset if the edge is
concave or convex.
The cut method takes in the bitmap data of the puzzle image and then returns a two
dimensional array of group objects. Each group object contains a one-piece object.
These groups are then merged as and when the player matches the pieces together.
public function cut(bmd:BitmapData):Array {
// The return array
var ret:Array = new Array();
var i:int, j:int;
var cols:int = bmd.width/IML.PIECE_SIZE;
 
Search WWH ::




Custom Search