Game Development Reference
In-Depth Information
protected function pieceLockAnimation():void {
var shape:Shape = new Shape();, .5);, 0, Math.max(width, height)/2);;
shape.x = width / 2;
shape.y = height / 2;
addChild(shape);, 1, { scaleX:2, scaleY:2, alpha:0,
onComplete:removeChild, onCompleteParams:[shape]} );
parent.setChildIndex(this, parent.numChildren 1);
override public function toString():String {
GamePiece: index =
+ index +
, currentIndex =
Finally, wrapping up the class are the methods to lock the piece
in place and also to move it. The pieceLockAnimation method is
another custom animation function, which could be substituted for
just about any other treatment. In this case, when a piece is locked,
it flashes a green (usually the color associated with a positive
move) square over the piece and fades it out.
Shape objects are a low-impact form of DisplayObject that are great to use
when all you need is something to draw in using the Graphics API or to
use as an overlay. Because they don
have to worry about them receiving or blocking mouse or keyboard events
that you need your container to get. Because they
t extend InteractiveObject, you don
re so simple they also
consume fewer resources, so if you didapuzzlewith100+pieces,you
t be consuming nearly as much in memory or rendering power.
The SourceImageEmbedded Class
Now that we have all the logic for the game itself and functional
pieces, the last component to this puzzle is the image itself. We
seen the ISourceImage interface that is used by the GameBoard
class to pull in a list of BitmapData objects. But how does the origi-
nal BitmapData get pulled in and then sliced? The answer is
It depends on the source of the image. If the images are
embedded in the FLA library, as in our example, the BitmapData is
just waiting there for us to instantiate. But for other sources, like
external image files or a camera feed, it
s a little more complicated.
ll start out by seeing how to use an embedded image. You may
Search Nedrilad ::

Custom Search