Skip to content

Instantly share code, notes, and snippets.

@hex13
Last active December 24, 2015 12:58
Show Gist options
  • Save hex13/6800874 to your computer and use it in GitHub Desktop.
Save hex13/6800874 to your computer and use it in GitHub Desktop.
spaceshooter, tutorial, step1
var images = {};
function loadImages(directory, fileNames, onComplete) {
var imagesLeft = fileNames.length;
fileNames.forEach(function(fileName) {
var img = new Image();
img.onload = function() {
imagesLeft--;
if (imagesLeft <= 0)
onComplete();
};
img.src = directory + '/' + fileName;
// z "spaceship.png" uzyskamy "spaceship", za pomoca funkcji substring
var unitName = fileName.substring(0, fileName.lastIndexOf('.'));
images[unitName] = img;
});
};
function initialize() {
console.log('initialize()');
console.log(images['player']);
console.log(images['ufo']);
};
$(document).ready(function() {
loadImages('images', ['player.png', 'ufo.png'], initialize);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment