Game Development Reference
In-Depth Information
them darker than larger ones. Values for movement speed and
rotation speed are then calculated based on the minimum and
maximum settings we observed earlier. Finally, the rock is cached
to the GPU as the last step in the process
we do this finally so
that the GPU doesn
'
thavetodrawitmultipletimesduetothe
changes we
ve made to its scale and color transform. Now, when-
ever this Rock is manipulated on the Stage, its rendering will be
handled solely by the graphics processor on the device.
'
public function reset():void
{
scaleX = scaleY = 1;
transform.colorTransform = new ColorTransform();
_movementSpeed = 0;
_rotationSpeed = 0;
_previousTime = 0;
_availableRocks.push(this);
cacheAsBitmapMatrix = null;
}
Acting as a counter to the init method, the class also has a reset
method that can be called to restore all of the key values of the
class to their default states. When other classes (specifically the
document class) are done using this instance, they will call this
method to tag it for recycling. Note that the Rock adds itself to the
static Vector list _avaialbleRocks . This will become important in the
next method we examine.
public static function getRock():Rock
{
if (_availableRocks.length)
{
var rock:Rock = _availableRocks.pop();
rock.init();
return rock;
}
else
{
return new Rock();
}
}
The static getRock method acts as the crux of the recycling process.
Instead of having Rocks get created by calling the constructor (which
will ultimately result in an untracked number of rock instances), this
method will check to see if there are any dormant rock instances
availablewhichcouldbere-used.Oncearockhasbecomeinactive
using the reset method, it is added to the pool of available instances. If
there are any items in this list, getRock plucks the object off the end of
Search Nedrilad ::




Custom Search