AssetPreloader

Preloads all asset files used in the game

  • Images
  • Sounds
  • JSON

Broadcasts events during the process so that other classes can keep track:

  • assetsloadupdate - A single item has just loaded, including a percentage of items loaded so far
  • assetsloaded - All items have finished loading
Author
  • Mark Mayes / mm-dev
License
  • GPL-3.0-only

Methods

(static) init()

Source
Initialise the preloader
  • Add all objects to be preloaded
  • Calculate totals
  • Set up event listener for items loading

(static) onComplete()

Source
Everything has finished preloading

Broadcast an assetsloaded event.

(static) onItemDone(event)

Source
An item has finished loading
  • Update count of total items loaded
  • Calculate count as a percentage (based on number of items ie size is not considered)
  • Broadcast the details in an assetsloadupdate event to be used eg by LoadingIndicator
  • Call onComplete() when all done
Parameters
Name Type Description
event Event
Name Type Description
detail object
Name Type Attributes Description
audioItemsLoaded string optional

Count of audio items loaded so far

imageItemsLoaded string optional

Count of image items loaded so far

jsonItemsLoaded string optional

Count of JSON items loaded so far