Game Development Reference
In-Depth Information
the Vector, reinitializes it (since it
s not being constructed again), and
returns it. If the list is empty (like at the start of the application), a
new rock is created and returned instead. In a moment, we
ll see how
this works in practice to eliminate unnecessary garbage collection.
public function update():void
if (_previousTime)
_deltaTime = (getTimer() - _previousTime)/1000;
rotation += _deltaTime * _rotationSpeed;
x += _deltaTime * _movementSpeed;
_previousTime = getTimer();
The final method in the class is an update method, which will
look very similar to the one in the Space class. It has the additional
rotation property set, which will make the rocks spin as they move. The Document Class
The main document class will drive this example since it is more of
a technical demonstration than anything else. It will be responsible
for placing all of the objects on screen, sending them update
events, and removing those that are no longer needed.
public class SpaceRocks extends Sprite
public static const ROCK_CREATION_INTERVAL:Number = 800;
private var _rockList:Dictionary = new Dictionary(true);
private var _rockTimer:Timer;
private var _space:Space;
public function SpaceRocks()
addEventListener(Event.ENTER_FRAME, onEnterFrame,
false, 0, true);
_space = new Space();
addChildAt(_space, 0);
_rockTimer = new Timer(ROCK_CREATION_INTERVAL);
onRockTimer, false, 0, true);
Search Nedrilad ::

Custom Search