Created
August 21, 2012 13:19
-
-
Save gj84/3415315 to your computer and use it in GitHub Desktop.
Images preload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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