9 years ago by dungeonmaster
I'm using fillRect to draw about 30,000 4 x 4px rectangles on each frame to an offscreen canvas and later copy it to the main canvas in the draw phase.
on update():
later in draw()
Although the speed is OK, I wonder if there is a faster way to make it. Even on my desktop gaming PC, FPS begins to drop after about 20,000~ tiles
on update():
this.bContext.clearRect(0,0,this.canvasWidth,this.canvasHeight); var ctx = this.bContext; //bContext is the context of my offscreen canvas var s = this.scale; //I use 4 for (var y = parcelY;y<parcelEndY;y++) { for (var x = parcelX;x<parcelEndX;x++) { var grainID = this.sandbox.parcel[y][x]; ctx.fillStyle = this.sandbox.gd.color[grainID]; ctx.fillRect((x-parcelX)*s,(y-parcelY)*s,s,s); } }
later in draw()
ig.system.context.drawImage(this.bCanvas,-offsetX,-offsetY);
Although the speed is OK, I wonder if there is a faster way to make it. Even on my desktop gaming PC, FPS begins to drop after about 20,000~ tiles