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.
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);
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.
This callback has a single parameter which is passed to it when it is triggered.
Returns the number of assets loaded.
var numberAssetsLoaded = assetTracker.getLoadedCount();
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();
Sets a callback function for an action to take each time the assetTracker updates its values and calculations.