Game Development Reference
In-Depth Information
_collisionGrid = new CollisionGrid(Number(_currentLevel.
@width), Number(_currentLevel.@height));
var assets:XMLList = _currentLevel.assets.children();
for (var i:int = 0; i < assets.length(); i++) {
_assetQueue.push(assets[i].@file);
}
var pe:PlatformerEvent = new PlatformerEvent(Platformer
Event.LEVEL_LOAD_COMPLETE);
dispatchEvent(pe);
loadNextAsset();
}
protected function levelError(e:IOErrorEvent):void {
trace( " PlatformEngine: Error Loading Level: " ,e.text);
}
protected function securityError(e:SecurityErrorEvent):void {
trace(
"
SecurityError:
"
,e.text);
}
//END LEVEL MANAGEMENT
Once the engine is created and initialized, it is ready to load a
level XML file. As such, there is a public method called loadLevel
that does just this. Once the level data is loaded and converted to an
XML object, a new CollisionGrid object is created, as well as a list of
all the necessary assets needed to play the level. Once this list is
complete, asset loading begins.
//ASSET MANAGEMENT
protected function loadNextAsset(e:Event = null):void {
var loader:Loader = new Loader();
var nextAsset:String = _assetQueue[_assets.length];
var context:LoaderContext = new LoaderContext(false,
_assetDomain);
loader.load(new URLRequest(_assetPath + nextAsset), context);
loader.contentLoaderInfo.addEventListener(Event.
COMPLETE, assetsLoaded, false, 0, true);
loader.contentLoaderInfo.addEventListener(Progress
Event.PROGRESS, assetLoadProgress, false, 0, true);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.
IO_ERROR, assetLoadError, false, 0, true);
loader.contentLoaderInfo.addEventListener(Security
ErrorEvent.SECURITY_ERROR, securityError, false, 0, true);
_assets.push(loader);
}
The loadNextAsset method is called each time one asset finishes
loading, until the entire manifest has been pulled into the engine.
Search Nedrilad ::




Custom Search