所以出于某种原因,我用于显示图像的 javascript 代码只能在 Chrome 中使用,而不能在任何其他浏览器中使用。
这是 JSFiddle:http://jsfiddle.net/LLy42oa0/
var snowflakeImage = new Image('');
snowflakeImage.ready = true;
snowflakeImage.src = 'http://i.imgur.com/W0rqcLP.png';
function drawSnowflakes() {
for(var i = 0; i < snowflakesInAir.length; i++) {
//Failsafe
if(snowflakesInAir[i].x > canvas.width || snowflakesInAir[i].y > canvas.height) {
i++;
}
context.drawImage(snowflakeImage, snowflakesInAir[i].x, snowflakesInAir[i].y);
}
}
任何帮助将不胜感激! 我试过切换到 image.onload() 但这似乎打破了我的 gameLoop。谢谢!
最佳答案
这是在 FireFox 中产生的错误:
IndexSizeError: Index or size is negative or greater than the allowed amount
,您可以找到问题的解决方案 here ,还有:
To clarify as well. Applying Math.round on the variables used in .drawImage() fixed this issue for me. Seems Firefox didn't like a fractioned number. – Justin Beaudry
关于javascript - context.drawImage 在 Chrome 中工作但在 Firefox 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27537963/