Table Of Contents

Previous topic

21.3. The AnimationManager Object

Next topic

21.5. The BoxTree Object

This Page

21.4. The AssetTracker Object

Utility object that provides a means to count the number of assets loaded at start up during development. Once game startup requirements have been finalised, this information can then be used to calculate the loading progress as the game downloads its assets.

21.4.1. Constructor

21.4.1.1. create

Summary

Creates the AssetTracker object.

This object can be used to determine the total number of assets that are loaded at startup.

By creating the the object using zero for the numberAssetsToLoad and true for the displayLog parameters, a log showing all the the names of the assets loaded and the count will be displayed in the console.

Once the total number of assets to load is known, the parameters for creating the object should then be modified.

Syntax

var assetTracker = AssetTracker.create(numberAssetsToLoad, displayLog);
numberAssetsToLoad
The number of assets that are going to be loaded. If this value is zero, no progress infomation is calculated.
displayLog
Boolean flag to enable logging information to console. Usefully while game is in development. Should be set for false before the game is released.

21.4.2. Method

21.4.2.1. eventOnLoadHandler

Summary

This callback has to be registered on the ‘eventOnLoad’ event with the request handler being used for the game.

This callback is used to perform tracking of loaded assets and progress calculations.

It is called once per asset loaded.

Syntax

requestHandler.addEventListener('eventOnload', assetTracker.eventOnLoadHandler);

This callback has a single parameter which is passed to it when it is triggered.

event
An object with the following fields
name
The name of the asset just loaded.
eventType
The event that triggered this callback.

21.4.2.2. getLoadedCount

Summary

Returns the number of assets loaded.

Syntax

var numberAssetsLoaded = assetTracker.getLoadedCount();

21.4.2.3. getLoadingProgress

Summary

Returns the current loading progress, a number between 0 and 1 inclusive. When all the requested assets have been loaded, this value will be equal to 1.

Syntax

var loadingProgress = assetTracker.getLoadingProgress();

21.4.2.4. setCallback

Summary

Sets a callback function for an action to take each time the assetTracker updates its values and calculations.

Syntax

assetTracker.setCallback(callback);