Game Development Reference
In-Depth Information
private static const MOVEMENT_SPEED_MAX:Number = 100;
//PIXELS PER SECOND
private static const MOVEMENT_SPEED_MIN:Number = 50;
//PIXELS PER SECOND
private static const ROTATION_SPEED_MAX:Number = 30;
//DEGREES PER SECOND
private static const ROTATION_SPEED_MIN:Number = -20;
//DEGREES PER SECOND
private static var _availableRocks:Vector. < Rock > = new
Vector. < Rock > ();
private var _movementSpeed:Number = 0;
private var _rotationSpeed:Number = 0;
private var _previousTime:int = 0;
private var _deltaTime:Number = 0;
public function Rock()
{
init();
}
private function init():void
{
var scaleRand:Number = Math.random();
scaleX = scaleY = scaleRand;
transform.colorTransform = new ColorTransform
(scaleRand, scaleRand, scaleRand);
_movementSpeed = (MOVEMENT_SPEED_MAX - MOVEMENT_
SPEED_MIN) * Math.random() + MOVEMENT_SPEED_MIN;
_rotationSpeed = (ROTATION_SPEED_MAX - ROTATION_
SPEED_MIN) * Math.random() + ROTATION_SPEED_MIN;
cacheAsBitmapMatrix = new Matrix();
}
The rocks will move and rotate at different random values, so
we define constants for the lower and upper limits of those ranges.
There is also a static Vector that we will keep track of every
instance of the Rock class that is created. The constructor does
nothing more than call the init method. This is one of the key com-
ponents to designing objects to be recycled; since you can
t call the
constructor on an object more than once, you need a way to dele-
gate any initialization to a method you can call whenever you
need. In the init function, a random value for the scale of the rock
is generated and also applied in a ColorTransform object. This will
create the appearance that smaller rocks are further away by tinting
'
Search Nedrilad ::




Custom Search