Game Development Reference
In-Depth Information
protected function pieceLockAnimation():void {
var shape:Shape = new Shape();
shape.graphics.beginFill(0x00CC00, .5);
shape.graphics.drawCircle(0, 0, Math.max(width, height)/2);
shape.graphics.endFill();
shape.x = width / 2;
shape.y = height / 2;
addChild(shape);
TweenLite.to(shape, 1, { scaleX:2, scaleY:2, alpha:0,
onComplete:removeChild, onCompleteParams:[shape]} );
parent.setChildIndex(this, parent.numChildren 1);
}
override public function toString():String {
return
"
GamePiece: index =
"
+ index +
"
, currentIndex =
"
+
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.
SHAPES
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
t
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
wouldn
'
'
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
'
ve
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
depends.
'
s a little more complicated.
We
'
ll start out by seeing how to use an embedded image. You may
Search Nedrilad ::




Custom Search