I am working on a game and have some performance issues by drawing one canvas on another using drawImage. According to Chrome Profiler, I spend 60% of my time only on this drawImage call and 10% on clearRect above it ...
The source canvas is about 3000x3000 (which is quite small, I would say), and the destination canvas is 1024x768.
I thought that instead of drawing all the tiles; walls etc. etc. every loop (which gives me about 15 frames per second), which will probably be faster to draw them all once on a screen canvas, and then draw it on my main canvas, then draw entities, etc. from above, It gives me ~ 30 frames per second, but ... is this the best I'm going to get when rendering software?
My rendering cycle is basically:
ctx.clearRect(0, 0, 1024, 768); ctx.beginPath(); ctx.drawImage(map, cam.position.i, cam.position.j, 1024, 768, 0, 0, 1024, 768); ctx.closePath(); ctx.save(); ctx.translate(-cam.position.i, -cam.position.j);
I canβt think of what to do, except that you start using WebGL (to take advantage of its hardware acceleration) or wait until vendors implement hardware acceleration for the 2d context. I would rather not do either, so any input would be appreciated.