Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better to have one big canvas or up to 100 small dynamically generated canvases?

I am working on a mobile web dice simulator. The initial prototype is here: http://dicewalla.com

I currently have one large canvas where I draw all the dice. I am planning to re-write the code in way that is more MVC and easier for me to update. I think it would be easier for me to generate a small canvas for each die object than to draw all of the dice on the big canvas and keep updating that big canvas.

My question is if there is a bad performance hit in having the browser create lots of little canvases vs one big one. It's hard to test locally, I was hoping someone here might know what the best practice is.

like image 937
Ben Brophy Avatar asked Aug 09 '12 12:08

Ben Brophy


People also ask

What is the purpose of the canvas element?

The HTML <canvas> element is used to draw graphics, on the fly, via JavaScript. The <canvas> element is only a container for graphics. You must use JavaScript to actually draw the graphics. Canvas has several methods for drawing paths, boxes, circles, text, and adding images.

What is a canvas area?

The canvas area represents an abstract drawing page where you define size and location of shapes with coordinates from (0,0) to (1000,1000). The origin point (0,0), is on the left-bottom of the drawing area. Figure 1. Canvas area diagram. The drawing area is defined in the form file with a CANVAS form item.


1 Answers

Multiple canvases usually allow for better performance as you're able to selectively re-render.

If you have only one canvas and want to update one die, you'll typically have to redraw the entire canvas. On the other hand, multiple canvases allow you to update only the dice that need to be redrawn. That's an increase in efficiency.

Further, you shouldn't see any noticeable difference in loading 1 canvas versus 100.

like image 162
Brian Ustas Avatar answered Sep 23 '22 06:09

Brian Ustas