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.
SpaceRocks.as: 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;
//MILLISECONDS
private var _rockList:Dictionary = new Dictionary(true);
private var _rockTimer:Timer;
private var _space:Space;
public function SpaceRocks()
{
//SETUP EVENT LISTENER
addEventListener(Event.ENTER_FRAME, onEnterFrame,
false, 0, true);
//CREATE SPACE
_space = new Space();
addChildAt(_space, 0);
//SETUP ROCK CREATION TIMER
_rockTimer = new Timer(ROCK_CREATION_INTERVAL);
_rockTimer.addEventListener(TimerEvent.TIMER,
onRockTimer, false, 0, true);
_rockTimer.start();
}
Search Nedrilad ::




Custom Search