API Docs for: 1.4.0
Show:

Kiwi.Files.Loader Class

Defined in: src\file\Loader.ts:10
Module: Files
Parent Module: Kiwi

Used for the loading of files and game assets. This usually happens when a State is at the 'loading' stage (executing the 'preload' method).

Constructor

Kiwi.Files.Loader

(
  • game
)
Kiwi.Files.Loader

Parameters:

  • game Kiwi.Game

    The game that this loader belongs to.

Returns:

Kiwi.Files.Loader:

This Object

Methods

_attemptToAddAudio

(
  • params
  • [onlyIfSupported=true]
)
Kiwi.Files.File private

This method firstly checks to see if the AUDIO file being loaded is supported or not by the browser/device before adding it to the loading queue. Returns a boolean if the audio file was successfully added or not to the file directory.

Parameters:

  • params Object
    • key String

      The key for the audio file.

    • url String

      The url of the audio to load.

    • [state=true] Kiwi.State optional

      The state this file should be for.

    • [fileStore] Kiwi.Files.FileStore optional
  • [onlyIfSupported=true] Boolean optional

    If the audio file should only be loaded if Kiwi detects that the audio file could be played.

Returns:

Kiwi.Files.File:

The file which was created.

_calculateNextFileSize

() private

Checks to see if all the file sizes have been retrieved. If so completes the "calculateQueuedSize" call. Otherwise requests the next file's details.

_detailsReceived

() private

Executed when by '_calculateNextFileSize' when the files information has been retrieved. Adds its calculated size to the _bytesTotal and executes the 'nextFileSize' method.

_fileQueueUpdate

(
  • file
  • [forceProgressCheck=false]
)
private

Defined in src\file\Loader.ts:442

Available since 1.2.0

Executed by files when they have successfully been loaded. This method checks to see if the files are in the file queue, and dispatches the appropriate events.

Parameters:

  • file Kiwi.Files.File

    The file which has been recently loaded.

  • [forceProgressCheck=false] Boolean optional

    If the progress of file loading should be checked, regardless of the file being in the queue or not.

_parallelFileComplete

(
  • file
)
private

Defined in src\file\Loader.ts:557

Available since 1.2.0

Executed when a file in the 'loadingParallel' lsit has been successfully loaded. Removes the file from the list and get the fileQueue to check its progress.

Parameters:

_queueFileComplete

(
  • file
)
private

Defined in src\file\Loader.ts:501

Available since 1.2.0

Executed when a file in the 'loadingQueue' has been successfully loaded. Removes the file from the loadingQueue and executes the '_startLoadingQueue' to start loading the next file.

Parameters:

_sortFile

(
  • file
)
private

Defined in src\file\Loader.ts:358

Available since 1.2.0

Sorts a file and places it into either the 'loadingParallel' or 'loadingQueue' depending on the method of loading it is using.

Parameters:

_startLoading

() private

Loops through the file queue and starts the loading process.

_startLoadingAllParallel

() private

Defined in src\file\Loader.ts:541

Available since 1.2.0

Starts loading all files which can be loaded in parallel.

_startLoadingParallel

(
  • params
)
private

Defined in src\file\Loader.ts:525

Available since 1.2.0

Starts loading a file which can be loaded in parallel.

Parameters:

_startLoadingQueue

() Boolean private

Defined in src\file\Loader.ts:474

Available since 1.2.0

Starts the loading process in the loadingQueue.

Returns:

Boolean:

Whether the first file is loading

_updateFileListInformation

() private

Called each time a file has processed whilst loading, or has just completed loading.

Calculates the new number of bytes loaded and the percentage of loading done by looping through all of the files.

addAudio

(
  • key
  • url
  • [storeAsGlobal=true]
  • [onlyIfSupported=true]
)
Kiwi.Files.File public

Creates a new File to store a audio piece. This method firstly checks to see if the AUDIO file being loaded is supported or not by the browser/device before adding it to the loading queue. You can override this behaviour and tell the audio data to load even if not supported by setting the 'onlyIfSupported' boolean to false. Also you can now pass an array of filepaths, and the first audio filetype that is supported will be loaded.

Parameters:

  • key String

    The key for the audio file.

  • url String

    The url of the audio to load. You can pass an array of URLs, in which case the first supported audio filetype in the array will be loaded.

  • [storeAsGlobal=true] Boolean optional

    If the file should be stored globally.

  • [onlyIfSupported=true] Boolean optional

    If the audio file should only be loaded if Kiwi detects that the audio file could be played.

Returns:

Kiwi.Files.File:

The file which was created.

addBinaryFile

(
  • key
  • url
  • [storeAsGlobal=true]
)
Kiwi.Files.File public

Creates a new File for a Binary file and adds it to the loading queue.

Parameters:

  • key String

    The key for the file.

  • url String

    The url to the Binary file.

  • [storeAsGlobal=true] Boolean optional

    If the file should be stored globally.

Returns:

Kiwi.Files.File:

The file which was created.

addFileToQueue

(
  • file
)
Boolean public

Defined in src\file\Loader.ts:265

Available since 1.2.0

Adds a file to the queue of files to be loaded. Files cannot be added whilst the queue is currently loading, the file to add is currently loading, or has been loaded before.

Parameters:

Returns:

Boolean:

If the file was added to the queue or not.

addImage

(
  • key
  • url
  • [width]
  • [height]
  • [offsetX]
  • [offsetY]
  • [storeAsGlobal=true]
)
Kiwi.Files.File public

Creates a new file for an image and adds a the file to loading queue.

Parameters:

  • key String

    The key for the file.

  • url String

    The url of the image to load.

  • [width] Number optional

    The width of the cell on the image to use once the image is loaded.

  • [height] Number optional

    The height of the cell on the image to use once the image is loaded.

  • [offsetX] Number optional

    An offset on the x axis of the cell.

  • [offsetY] Number optional

    An offset of the y axis of the cell.

  • [storeAsGlobal=true] Boolean optional

    If the image should be stored globally or not.

Returns:

Kiwi.Files.File:

The file which was created.

addJSON

(
  • key
  • url
  • [storeAsGlobal=true]
)
Kiwi.Files.File public

Creates a new File to store JSON and adds it to the loading queue.

Parameters:

  • key String

    The key for the file.

  • url String

    The url to the json file.

  • [storeAsGlobal=true] Boolean optional

    If the file should be stored globally.

Returns:

Kiwi.Files.File:

The file which was created.

addSpriteSheet

(
  • key
  • url
  • frameWidth
  • frameHeight
  • [numCells]
  • [rows]
  • [cols]
  • [sheetOffsetX]
  • [sheetOffsetY]
  • [cellOffsetX]
  • [cellOffsetY]
  • [storeAsGlobal=true]
)
Kiwi.Files.File public

Creates a new file for a spritesheet and adds the file to the loading queue.

Parameters:

  • key String

    The key for the file.

  • url String

    The url of the image to load.

  • frameWidth Number

    The width of a single cell in the spritesheet.

  • frameHeight Number

    The height of a single cell in the spritesheet.

  • [numCells] Number optional

    The number of cells that are in this spritesheet.

  • [rows] Number optional

    The number of cells that are in a row.

  • [cols] Number optional

    The number of cells that are in a column.

  • [sheetOffsetX] Number optional

    The offset of the whole spritesheet on the x axis.

  • [sheetOffsetY] Number optional

    The offset of the whole spritesheet on the y axis.

  • [cellOffsetX] Number optional

    The spacing between each cell on the x axis.

  • [cellOffsetY] Number optional

    The spacing between each cell on the y axis.

  • [storeAsGlobal=true] Boolean optional

Returns:

Kiwi.Files.File:

The file which was created.

addTextFile

(
  • key
  • url
  • [storeAsGlobal=true]
)
Kiwi.Files.File public

Creates a new File to store a text file and adds it to the loading queue.

Parameters:

  • key String

    The key for the file.

  • url String

    The url to the text file.

  • [storeAsGlobal=true] Boolean optional

    If the file should be stored globally.

Returns:

Kiwi.Files.File:

The file which was created.

addTextureAtlas

(
  • key
  • imageUrl
  • jsonID
  • jsonURL
  • [storeAsGlobal=true]
)
Kiwi.Files.File public

Creates new file's for loading a texture atlas and adds those files to the loading queue.

Parameters:

  • key String

    The key for the image file.

  • imageUrl String

    The url of the image to load.

  • jsonID String

    A key for the JSON file.

  • jsonURL String

    The url of the json file to load.

  • [storeAsGlobal=true] Boolean optional

    If hte files should be stored globally or not.

Returns:

Kiwi.Files.File:

The file which was created.

addXML

(
  • key
  • url
  • [storeAsGlobal=true]
)
Kiwi.Files.File public

Creates a new File to store XML and adds it to the loading queue.

Parameters:

  • key String

    The key for the file.

  • url String

    The url to the xml file.

  • [storeAsGlobal=true] Boolean optional

    If the file should be stored globally.

Returns:

Kiwi.Files.File:

The file which was created.

boot

() public

The boot method is executed when the DOM has successfully loaded and we can now start the game.

calculateBytes

(
  • [value]
)
Boolean public

Quick way of getting / setting the private variable 'calculateBytes' To be made into a public variable once removed.

Parameters:

  • [value] Boolean optional

Returns:

Boolean:

calculateQueuedSize

(
  • callback
  • [context=null]
)
public

Loops through the file queue and gets file information (filesize, ETag, filetype) for each.

To get accurate information about the bytesLoaded, bytesTotal, and the percentLoaded set the 'calculateBytes' property to true, as the loader will automatically execute this method before hand.

Can only be executed when the file queue is not currently loading.

Parameters:

  • callback Any
  • [context=null] Any optional

clearQueue

() public

Defined in src\file\Loader.ts:324

Available since 1.2.0

Clears the file queue of all files.

complete

() Boolean deprecated public

Defined in src\file\Loader.ts:1353

Deprecated: Use 'percentLoaded' instead. Deprecated as of 1.2.0

Returns a boolean indicating if everything in the loading que has been loaded or not.

Returns:

Boolean:

destroy

() public

Flags this loader for garbage collection. Only use this method if you are SURE you will no longer need it. Otherwise it is best to leave it alone.

getBytesLoaded

() Number deprecated public

Defined in src\file\Loader.ts:1381

Deprecated: Use 'bytesLoaded' instead. Deprecated as of 1.2.0

Returns the total number of bytes that have been loaded so far from files in the file queue.

Returns:

Number:

getPercentLoaded

() Number deprecated public

Defined in src\file\Loader.ts:1341

Deprecated: Use 'percentLoaded' instead. Deprecated as of 1.2.0

Returns a percentage of the amount that has been loaded so far.

Returns:

Number:

init

(
  • [progress=null]
  • [complete=null]
  • [calculateBytes=false]
)
deprecated public

Defined in src\file\Loader.ts:1304

Deprecated: Deprecated as of 1.2.0

Initialise the properities that are needed on this loader. Recommended you use the 'onQueueProgress' / 'onQueueComplete' signals instead.

Parameters:

  • [progress=null] Any optional

    Progress callback method.

  • [complete=null] Any optional

    Complete callback method.

  • [calculateBytes=false] Boolean optional

loadFile

() public

Starts the process of loading a file outside of the regular queue loading process. Callbacks for load completion need to be added onto the file via 'onComplete' Signal.

objType

() String public

The type of object this is.

Returns:

String:

"Loader"

onQueueComplete

() public

Defined in src\file\Loader.ts:81

Available since 1.2.0

A Signal which dispatches callbacks when all files in the 'loadingList' have been loaded. When adding callbacks make sure to 'remove' them (or to use the 'addOnce' method) otherwise will fire when other sections use the loader.

onQueueProgress

() public

Defined in src\file\Loader.ts:93

Available since 1.2.0

A Signal which dispatches callbacks each time a file in the 'loadingList' have been loaded. Callbacks dispatched are passed the following arguments in order.

  1. percent - The percentage of files loaded. A number from 0 - 100
  2. bytesLoaded - The number of bytes loaded
  3. file - The latest file that was loaded. First call will be null.

When adding callbacks make sure to 'remove' them (or to use the 'addOnce' method) otherwise will fire when other sections use the loader.

removeFileFromQueue

(
  • file
)
Boolean public

Defined in src\file\Loader.ts:292

Available since 1.2.0

Removes a file from the file queue. Files cannot be removed whilst the queue is loading.

Parameters:

Returns:

Boolean:

If the file was added to the queue or not.

start

(
  • [calculateBytes]
)
public

Defined in src\file\Loader.ts:184

Available since 1.2.0

Starts loading all the files which are in the file queue.

To accurately use the bytesLoaded or bytesTotal properties you will need to set the 'calculateBytes' boolean to true. This may increase load times, as each file in the queue will firstly make XHR HEAD requests for information.

When 'calculateBytes' is true the percentLoaded will be the bytesLoaded / bytesTotal. Otherwise it is based on the filesLoaded / numberOfFilesToLoad.

Parameters:

  • [calculateBytes] Boolean optional

    Setter for the 'calculateBytes' property.

startLoad

() deprecated public

Defined in src\file\Loader.ts:1331

Deprecated: Use 'start' instead. Deprecated as of 1.2.0

Loops through all of the files that need to be loaded and start the load event on them.

Properties

_bytesLoaded

Number private

The number of bytes loaded of files in the file queue.

_bytesTotal

Number private

Total file size (in bytes) of all files in the queue to be loaded.

_calculateBytes

Boolean private

If the number of bytes for each file should be calculated before the queue starts loading. If true each file in the queue makes a XHR HEAD request first to get the total values.

_completeFiles

Number private

The number of files in the file queue that have been updated.

Default: 0

_currentFileIndex

Number private

The index of the current file in the filelist thats size is being retrieved.

_fileQueueLoading

Boolean private

Defined in src\file\Loader.ts:111

Available since 1.2.0

A flag indicating if the files inside the file queue are loading or not.

Default: false

_loadingList

Array private

Defined in src\file\Loader.ts:69

Available since 1.2.0

List of files that are to be loaded. These files will be placed in the '_loadingQueue' or '_loadingParallel' lists when the queue is told to 'start' loading.

_loadingParallel

Array private

Defined in src\file\Loader.ts:46

Available since 1.2.0

A list of files that can be loaded in parallel to one another. This list of files are currently being loaded.

_loadingQueue

Array private

Defined in src\file\Loader.ts:57

Available since 1.2.0

List of files that cannot load in parallel to one another and so need to wait for previous files to load first. Generally files loaded via XHR.

bytesLoaded

Number public

Defined in src\file\Loader.ts:654

Available since 1.2.0

READ ONLY: Returns the total number of bytes for the files in the file queue.

If you are using this make sure you set the 'calculateBytes' property to true OR execute the 'calculateQueuedSize' method. Otherwise files that are loaded via tags will not be accurate!

Default: 0

bytesTotal

Number public

Defined in src\file\Loader.ts:629

Available since 1.2.0

READ ONLY: Returns the total number of bytes for the files in the file queue. Only contains a value if you use the 'calculateBytes' and are loading files OR if you use the 'calculateQueuedSize' method.

Default: 0

enableParallelLoading

Boolean public

Defined in src\file\Loader.ts:150

Available since 1.2.0

When enabled, files which can be loaded in parallel (those which are loaded via tags) will be loaded at the same time.

The default behaviour is to have the files loading in a queued fashion instead of one after another.

Default: false

fileQueueLoading

Boolean public

Defined in src\file\Loader.ts:122

Available since 1.2.0

READ ONLY: A flag indicating if the files inside the file queue are loading or not.

Default: false

game

Kiwi.Game public

The game this loader is attached to.

onQueueSizeCalculate

Any private

Callback for when the total number of bytes of the files in the file list has been calculated.

onSizeContext

Any private

Context that the onSizeCallback should be executed in.

percentLoaded

Number public

Defined in src\file\Loader.ts:137

Available since 1.2.0

When 'calculateBytes' is true the percentLoaded will be the bytesLoaded / bytesTotal. Otherwise it is based on the filesLoaded / numberOfFilesToLoad.