Game Development Reference
In-Depth Information
Note that the Loader has a specific LoaderContext object created
for it, which directs it to place the Loader
s class definitions in a
common ApplicationDomain. Each Loader also has a progress
event linked to it, which we will discuss next.
'
protected function assetLoadProgress(e:ProgressEvent):void {
var baseCompletion:Number = 100 * (_assets.length-1)/
_assetQueue.length;
var currentProgress:Number = (100/_assetQueue.length) *
(e.bytesLoaded/e.bytesTotal);
var bytesLoaded:int = Math.round(baseCompletion +
currentProgress);
var pe:ProgressEvent = new ProgressEvent(ProgressEvent.
PROGRESS, false, false, bytesLoaded, 100);
dispatchEvent(pe);
}
To create an accurate percentage of how much of the level assets
have loaded (without knowing the file size of each one), we have to
create a custom ProgressEvent. It takes into account the number of
items to load and the individual progress of each asset to create an
event with somewhere between 0 and 100 bytes loaded, which repre-
sents the percent loaded. Naturally, if the asset files are dramatically
different in size, this means of measuring completion will seem a little
erratic, but it will be as accurate as we can get without loading all of
the files at once (which can choke on some Internet connections).
protected function assetsLoaded(e:Event):void {
if (_assets.length
_assetQueue.length) {
loadNextAsset();
return;
<
}
var pe:PlatformerEvent = new PlatformerEvent(Platformer
Event.ASSET_LOAD_COMPLETE);
dispatchEvent(pe);
createLevel();
}
protected function assetLoadError(e:IOErrorEvent):void {
trace( " PlatformEngine: Error Loading Asset: " ,_assetQueue
[_assets.length-1]);
}
protected function getAssetClass(assetName:String):Class {
if (_assetDomain.hasDefinition(assetName)) {
return _assetDomain.getDefinition(assetName) as
Class;
}
Search Nedrilad ::




Custom Search