Checking images are loaded before rendering them
Posted: Sat Jul 23, 2016 2:43 pm
Hi
I am currently trying to fix this piece of code, it should once run check if images.room.moveroom.ready is true then render the image. But the ready does not change. Is there any way of implementing this without using jquery?
I am currently trying to fix this piece of code, it should once run check if images.room.moveroom.ready is true then render the image. But the ready does not change. Is there any way of implementing this without using jquery?
Code: Select all
var createImage = function (src) {
var imgReady = false
var img = new Image();
img.onload = function () {
imgReady = true;
}
img.src = src;
var result = {img: img, ready: imgReady};
return result;
};
var images = {
room : {
moveroom: createImage("/images/rooms/moveroom.png"),
questI: createImage("./images/rooms/questI.png"),
questQ: createImage("./images/rooms/questQ.png")
}
};