Game Development Reference
In-Depth Information
loadQuadrant(m_quads[cqi+1] as Quadrant);
unloadQuadrant(m_quads[cqi-2] as Quadrant);
}
The two private methods that actually load and unload the quadrants are listed next:
private function loadQuadrant(q:Quadrant):void {
var items:Array = null;
var item:Sprite = null;
var i:int;
if ( q == null )
return;
if ( !q.load(m_pulse) )
return;
items = q.getItems();
for ( i=0; i<items.length; i++ ) {
item = items[i];
addChild(item);
}
}
private function unloadQuadrant(q:Quadrant):void {
var items:Array = null;
var item:Item = null;
var i:int;
if ( q == null )
return;
if ( !q.unload() )
return;
items = q.getItems();
for ( i=0; i<items.length; i++ ) {
item = items[i] as Item;
removeChild(item);
}
}
In each case, we first check if the quadrant is already in the loaded or unloaded state.
If it is already in the required state, we simply return from the method. If not, in the
case of load, we get all the items in that quadrant and add them as a child of
the racetrack, and in the case of unload, we simply remove the items from the
display list.
 
Search WWH ::




Custom Search