Game Development Reference
In-Depth Information
var rect:Rectangle = new Rectangle(i *
pieceWidth, j * pieceHeight, pieceWidth,
pieceHeight);
pieceBitmap.copyPixels(_sourceBitmap,
rect, new Point());
_pieceList.push(pieceBitmap);
}
}
addEventListener(Event.ENTER_FRAME, updateImages, false,
0, true);
return _pieceList;
}
Once again, you probably notice a number of similarities to the
image version of this class, except for two main differences. The
first is that instead of simply instantiating a new BitmapData image
from a class, we have to create an empty one and draw the video
into it. The second is that once the list is done being created, an
ENTER_FRAME listener is added to call a method called update-
Images, which we
'
ll look at next.
protected function updateImages(e:Event):void {
_sourceBitmap.dispose();
_sourceBitmap = new BitmapData(_video.width, _video.
height);
_sourceBitmap.draw(_video);
var pieceBitmap:BitmapData;
var pieceWidth:int = Math.floor(_sourceBitmap.width /
_columns);
var pieceHeight:int = Math.floor(_sourceBitmap.height /
_rows);
for (var j:int = 0; j < _rows; j++) {
for (var i:int = 0; i < _columns; i++) {
pieceBitmap = _pieceList[i + (j *
_columns)];
var rect:Rectangle = new Rectangle(i *
pieceWidth, j * pieceHeight, pieceWidth,
pieceHeight);
pieceBitmap.copyPixels(_sourceBitmap,
rect, new Point());
}
}
}
Most of this function mirrors the same process we did in get-
Images, except that we now dispose of the original source image
and draw a new one on every frame loop (to keep up with the
changing camera image). Also, instead of creating a new list of
Search Nedrilad ::




Custom Search