gpt4 book ai didi

javascript - context.drawImage 在 Chrome 中工作但在 Firefox 中不工作

转载 作者:太空宇宙 更新时间:2023-11-03 17:49:38 24 4
gpt4 key购买 nike

所以出于某种原因,我用于显示图像的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com