var canvas = null;
var context = null;
var img = null;
var frames = [];
var assets = [];
var imgLoadCount = 0;
setup = function (fileArray) {
assets = fileArray;
//Loading an image
for(var i = 0; i < assets.length; i++) {
console.log(i);
frames.push(new Image()); // declare image object
frames[i].onload = onImageLoad(assets.length); //declare onload method
frames[i].src = URL.createObjectURL(assets[i]); //set url
}
};
onImageLoad = function (len) {
console.log("IMAGE!!!");
canvas = document.getElementById("my_canvas"); //creates a canvas element
context = canvas.getContext('2d');
canvas.width = window.innerWidth; //for full screen
canvas.height = window.innerHeight;
var x, y, numTilesRow;
numTilesRow = 10;
imgLoadCount++;
console.log("imgLoadCount = " + frames.length + ", length = " + len);
if(imgLoadCount != len) {
return;
}
for(var index = 0; index < len; index++) {
x = Math.floor((index % numTilesRow));
y = Math.floor(index/numTilesRow);
worldX = x * numTilesRow;
worldY = y * numTilesRow;
context.drawImage(frames[index], worldX, worldY);
}
};
我不能告诉的drawImage为什么突然停止插入代码 后工作,如果(imgLoadCount = LEN!){回报;}这将确保所有图像加载正确。请有人帮我找到解决这个问题的方法。的drawImage不工作
愚蠢的问题,但你检查看到'imgLoadCount == len'? – 2013-04-29 06:54:32
是的,下面的for循环只在imgLoad === len时才运行,这是所有图像加载时的情况,因此drawImage需要在循环的每次运行中绘制图像,但不会。这就是我需要帮助的地方。 – user1523292 2013-04-29 07:24:18