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 create


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.


var assetTracker = AssetTracker.create(numberAssetsToLoad, displayLog);
The number of assets that are going to be loaded. If this value is zero, no progress infomation is calculated.
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 eventOnLoadHandler


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.


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

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

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


Returns the number of assets loaded.


var numberAssetsLoaded = assetTracker.getLoadedCount(); getLoadingProgress


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.


var loadingProgress = assetTracker.getLoadingProgress(); setCallback


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