Kiwi.Files.Loader Class
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
Parameters:
-
game
Kiwi.GameThe game that this loader belongs to.
Returns:
This Object
Item Index
Methods
Methods
addAudio
-
key
-
url
-
[storeAsGlobal=true]
-
[onlyIfSupported=true]
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
StringThe key for the audio file.
-
url
StringThe 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 optionalIf the file should be stored globally.
-
[onlyIfSupported=true]
Boolean optionalIf the audio file should only be loaded if Kiwi detects that the audio file could be played. Set this to fa
addBinaryFile
-
key
-
url
-
[storeAsGlobal=true]
Creates a new File for a Binary file and adds it to the loading queue.
Parameters:
-
key
StringThe key for the file.
-
url
StringThe url to the Binary file.
-
[storeAsGlobal=true]
Boolean optionalIf the file should be stored globally.
addImage
-
key
-
url
-
[width]
-
[height]
-
[offsetX]
-
[offsetY]
-
[storeAsGlobal=true]
Creates a new file for an image and adds a the file to loading queue.
Parameters:
-
key
StringThe key for the file.
-
url
StringThe url of the image to load.
-
[width]
Number optionalThe width of the cell on the image to use once the image is loaded.
-
[height]
Number optionalThe height of the cell on the image to use once the image is loaded.
-
[offsetX]
Number optionalAn offset on the x axis of the cell.
-
[offsetY]
Number optionalAn offset of the y axis of the cell.
-
[storeAsGlobal=true]
Boolean optionalIf the image should be stored globally or not.
addJSON
-
key
-
url
-
[storeAsGlobal=true]
Creates a new File to store JSON and adds it to the loading queue.
Parameters:
-
key
StringThe key for the file.
-
url
StringThe url to the json file.
-
[storeAsGlobal=true]
Boolean optionalIf the file should be stored globally.
addSpriteSheet
-
key
-
url
-
frameWidth
-
frameHeight
-
[numCells]
-
[rows]
-
[cols]
-
[sheetOffsetX]
-
[sheetOffsetY]
-
[cellOffsetX]
-
[cellOffsetY]
-
[storeAsGlobal=true]
Creates a new file for a spritesheet and adds the file to the loading queue.
Parameters:
-
key
StringThe key for the file.
-
url
StringThe url of the image to load.
-
frameWidth
NumberThe width of a single cell in the spritesheet.
-
frameHeight
NumberThe height of a single cell in the spritesheet.
-
[numCells]
Number optionalThe number of cells that are in this spritesheet.
-
[rows]
Number optionalThe number of cells that are in a row.
-
[cols]
Number optionalThe number of cells that are in a column.
-
[sheetOffsetX]
Number optionalThe offset of the whole spritesheet on the x axis.
-
[sheetOffsetY]
Number optionalThe offset of the whole spritesheet on the y axis.
-
[cellOffsetX]
Number optionalThe spacing between each cell on the x axis.
-
[cellOffsetY]
Number optionalThe spacing between each cell on the y axis.
-
[storeAsGlobal=true]
Boolean optional
addTextFile
-
key
-
url
-
[storeAsGlobal=true]
Creates a new File to store a text file and adds it to the loading queue.
Parameters:
-
key
StringThe key for the file.
-
url
StringThe url to the text file.
-
[storeAsGlobal=true]
Boolean optionalIf the file should be stored globally.
addTextureAtlas
-
key
-
imageUrl
-
jsonID
-
jsonURL
-
[storeAsGlobal=true]
Creates new file's for loading a texture atlas and adds those files to the loading queue.
Parameters:
-
key
StringThe key for the image file.
-
imageUrl
StringThe url of the image to load.
-
jsonID
StringA key for the JSON file.
-
jsonURL
StringThe url of the json file to load.
-
[storeAsGlobal=true]
Boolean optionalIf hte files should be stored globally or not.
addToBytesTotal
-
file
Adds the number of bytes that a File is to the total number of bytes loaded.
Parameters:
-
file
Kiwi.Files.File
addXML
-
key
-
url
-
[storeAsGlobal=true]
Creates a new File to store XML and adds it to the loading queue.
Parameters:
-
key
StringThe key for the file.
-
url
StringThe url to the xml file.
-
[storeAsGlobal=true]
Boolean optionalIf the file should be stored globally.
attemptToAddAudio
-
key
-
url
-
[storeAsGlobal=true]
-
[onlyIfSupported=true]
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:
-
key
StringThe key for the audio file.
-
url
StringThe url of the audio to load.
-
[storeAsGlobal=true]
Boolean optionalIf the file should be stored globally.
-
[onlyIfSupported=true]
Boolean optionalIf the audio file should only be loaded if Kiwi detects that the audio file could be played. Set this to fa
boot
()
public
The boot method is executed when the DOM has successfully loaded and we can now start the game.
calculateBytes
-
[value]
If true (and xhr/blob is available) the loader will get the bytes total of each file in the queue to give a much more accurate progress report during load If false the loader will use the file number as the progress value, i.e. if there are 4 files in the queue progress will get called 4 times (25, 50, 75, 100)
Parameters:
-
[value]
Boolean optional
Returns:
complete
()
Boolean
public
Returns a boolean indicating if everything in the loading que has been loaded or not.
Returns:
fileLoadComplete
-
file
Executed when a file has been successfully loaded. This method then decides whether loading is complete or we need to load the next file.
Parameters:
-
file
Kiwi.Files.File
fileLoadProgress
-
file
Executed whilst a file is being loaded.
Parameters:
-
file
Kiwi.Files.File
getBytesLoaded
()
Number
public
Returns the total number of bytes that have been loaded so far.
Returns:
getNextFileSize
()
private
Calculates the size of the new file that is to be loaded.
getPercentLoaded
()
Number
public
Returns a percentage of the amount that has been loaded so far.
Returns:
init
-
[progress=null]
-
[complete=null]
-
[calculateBytes=false]
Initialise the properities that are needed on this loader.
Parameters:
-
[progress=null]
Any optionalProgress callback method.
-
[complete=null]
Any optionalComplete callback method.
-
[calculateBytes=false]
Boolean optional
nextFile
()
private
Starts the loading of the next file in the list.
objType
()
String
public
The type of object that this is.
Returns:
"Loader"
startLoad
()
public
Loops through all of the files that need to be loaded and start the load event on them.
Properties
_bytesCurrent
Number
private
Total number of bytes loaded from last completed file
_bytesLoaded
Number
private
Total number of bytes loaded so far (out of _bytesTotal)
_bytesTotal
Number
private
Total file size (in bytes) of all files to be loaded - only set if calculateBytes is true
_calculateBytes
Boolean
private
If a real byte value calculation will be made prior to the load (much smoother progress bar but costs HEAD calls x total file count)
Default: true
_complete
Boolean
private
Everything in the queue loaded?
_currentFile
Number
private
The most recently loaded file (out of the total)
_fileChunk
Number
private
When using the tag loader we don't have a byte total, just a X of files total - this holds the percentage each file from that total is worth
_fileList
Array
private
A list of all of the files that need to be loaded. Each item in the array is of the type Kiwi.Files.File.
_fileTotal
Number
private
Total number of files to be loaded
_loadList
Array
private
A list of all of the files that have been loaded. Each item in the array is of the type Kiwi.Files.File.
_onCompleteCallback
Function
private
A callback that is to be called when the loader has finished loading files.
_onProgressCallback
Function
private
A callback that is to be called while the loader is in the process of loading files.
_percentLoaded
Number
private
The total % of the current queue that has been loaded