我有一个100x100像素的平铺地图。当我尝试在浏览器上打开游戏时,页面冻结,因为要绘制10000个图块。您怎么能毫无问题地绘制这么多的瓷砖。
我的draw()函数:

this.draws = function(){

    for(j = 0; j < 10000; j++){

        this.i = levels[1][1][j] - 17*Math.floor(levels[1][1][j]/17)
        game.ctx.fillStyle = "red"
        game.ctx.drawImage(game.tiileset,(this.i-1)*this.cellW,(Math.floor(levels[1][1][j]/17))*16,this.cellW,this.cellW,(j-100*Math.floor(j/100))*this.cellW-1,(Math.floor(j/100)+1)*this.cellW,this.cellW,this.cellW)


    }

}

最佳答案

我不确定您要做什么,但好像您正在将图像中的每个像素绘制到画布上。

如果确实如此,我建议您立即绘制整个图像。

如果没有,我真的需要一个更详细的问题,也许对代码中的数学有更多的解释。

哦,是的,不要忘记分号。

10-05 20:50
查看更多