Game Development Reference
In-Depth Information
piece.image = imageData[i];
piece.x = piece.width * (i % _columns);
piece.y = piece.height * Math.floor(i / _columns);
_pieces.push(piece);
addChild(piece as DisplayObject);
}
}
public function shuffleBoard():void {
randomize(_pieces);
for (var i:int = 0; i < _pieces.length; i++) {
movePiece(_pieces[i], i);
}
}
The createBoard function is the process by which the image
dataispulledfromitssourceandinsertedintogamepieces.For
every piece of image data, a new game piece is created and
added to the Stage. The result of createBoard is a reproduction
of the original image, but in adjacent pieces rather than a single
bitmap. The shuffleBoard method is used to mix up the images
and move them from their original places. We
ll, shortly, review
the randomize and movePiece methods it calls. The two methods
above are separated in order to allow the game to display the
original image for a period, if needed, before rearranging the
board.
'
public function activate():void {
for each (var piece:IGamePiece in _pieces) {
piece.activate();
piece.addEventListener(MouseEvent.CLICK,
pieceClicked, false, 0, true);
}
}
public function deactivate():void {
for each (var piece:IGamePiece in _pieces) {
piece.deactivate();
piece.removeEventListener(MouseEvent.CLICK,
pieceClicked);
}
}
public function cleanUp():void {
_boardImage.cleanUp();
_pieces = null;
}
Search Nedrilad ::




Custom Search