Game Development Reference
In-Depth Information
var rows:int = bmd.height/IML.PIECE_SIZE;
// Init the puzzle sprite space
PieceSprite.initMax(cols, rows);
// Generate shape for the puzzle pieces
var shapes:Array = ShapeGen.gen(cols, rows);
var id:int = 0;
for ( i=0; i<cols; i++) {
for (j=0; j<rows; j++ ) {
id++;
// Get the mask to applied
var mask:Mask;
mask = Mask.getMask(shapes[i][j]);
// Determine the x, y, width and height
// cut out of the puzzle image
var x:Number = 0, y:Number = 0;
var wide:Number;
var high:Number;
wide = mask.bmd.width;
high = mask.bmd.height;
// Determine the x & y for the piece
x = i*IML.PIECE_SIZE;
if ( i > 0 ) {
// Account for edge
x -= mask.ox;
}
else
x = -1;
y = j*IML.PIECE_SIZE;
if ( j > 0 ) {
y -= mask.oy;
}
else
y = -1;
var rect:Rectangle;
rect = new Rectangle(x, y, wide, high);
var pd:BitmapData;
pd = new BitmapData(wide, high, true, 0);
// Merge the shape with the
// part of the puzzle picture
pd.copyPixels(bmd,
rect,
new Point(0, 0),
mask.bmd,
new Point(0, 0),
 
Search WWH ::




Custom Search