Skip to content

Instantly share code, notes, and snippets.

@gj84
Created August 21, 2012 13:19
Show Gist options
  • Save gj84/3415315 to your computer and use it in GitHub Desktop.
Save gj84/3415315 to your computer and use it in GitHub Desktop.
Images preload
function preLoad(){
nameimages = new Array('nimage0','nimage1','nimage2','nimage3','nimagen');
images = {};
loadAllImages();
function loadAllImages(){
for (name in nameimages){
images[nameimages[name]] = new Image();
images[nameimages[name]].onload = function() {
resourceLoaded();
}
images[nameimages[name]].src = "images/" + nameimages[name] + ".png";
}
}
var totalResources = nameimages.length;
var numResourcesLoaded = 0;
function resourceLoaded() {
numResourcesLoaded += 1;
if(numResourcesLoaded === totalResources) {
main();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment