public void Crafty.load(Array assets, Function onLoad[, Function onProgress, Function onError])
Preloader for all assets. Takes an array of URLs and
adds them to the Crafty.assets
object.
Files with suffixes in image_whitelist
(case insensitive) will be loaded.
If Crafty.support.audio
is true
, files with the following suffixes mp3
, wav
, ogg
and mp4
(case insensitive) can be loaded.
The onProgress
function will be passed on object with information about
the progress including how many assets loaded, total of all the assets to
load and a percentage of the progress.
{ loaded: j, total: total, percent: (j / total * 100) ,src:src})
onError
will be passed with the asset that couldn't load.
When onError
is not provided, the onLoad is loaded even some assets are not successfully loaded. Otherwise, onLoad will be called no matter whether there are errors or not.
Crafty.load(["images/sprite.png", "sounds/jump.mp3"],
function() {
//when loaded
Crafty.scene("main"); //go to main scene
Crafty.audio.play("jump.mp3"); //Play the audio file
},
function(e) {
//progress
},
function(e) {
//uh oh, error loading
}
);