Reputation: 77
I have a 100x100 px Tile Map. When I try to open my game on my browser the page freezes because there are to draw 10000 tiles. How can you draw so much tiles without problems. My draw() function:
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)
}
}
Upvotes: 1
Views: 796
Reputation: 111
I´m unsure of what you´re trying to do but it looks like you´re drawing each pixel from the image to the canvas.
If that is indeed the case I suggest you just draw the whole image at once.
If not, I would really need a more elaborated question perhaps with more explanations on the math in your code.
Oh yes don´t forget semicolons.
Upvotes: 1