Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 multiple canvas on a single page

Tags:

html

canvas

If we use multiple <canvas> on a single html page does it hamper the performance of the application that is being developed and does the code get very bulky and require more time to load the page?

like image 644
Nitesh Avatar asked Oct 26 '10 05:10

Nitesh


People also ask

Can you have more than one canvas on HTML page?

A webpage may contain multiple canvas elements. Each canvas may have an id using which you may target a specific canvas through JavaScript. Each canvas element has a 2D Context. This again has objects, properties, and methods.

Can you have multiple canvas?

Welcome to the Canvas Community. And Yes, you can have multiple Canvas accounts associated in the app.

Is HTML5 canvas still used?

The HTML5 canvas has the potential to become a staple of the web, enjoying ubiquitous browser and platform support in addition to widespread webpage support, as nearly 90% of websites have ported to HTML5.

Does HTML canvas have layers?

Introduction. Often, in 2D games or when rendering HTML5 canvas, optimization is performed so multiple layers are used to build a composite scene. In low-level rendering such as OpenGL or WebGL, rendering is performed by clearing and drawing to a scene every frame.


1 Answers

Sometimes multiple canvases results in better performance. It's best to test if you can afford the time.

Say you are making a program that has items on the screen and allows the user to draw a selection box.

With one canvas, to draw the selection box you'd have to redraw all of the elements over and over to update the selection box that the user sees since they are all on the same canvas.

Or, you can have two canvases, one with the objects and then another one in front for things like "tools" (like the selection box graphics). Here two canvases may be more efficient.

Other times you may want to have a background that changes very rarely and foreground objects that change all the time. Instead of redrawing all of them at 60 frames per second, you make a background canvas and foreground canvas, and only have the foreground's objects redraw at the fast speed. Here two canvases ought to be more efficient than one, but it may be more optimal to "cache" that background canvas as an image and drawing the image first each frame.

like image 176
Simon Sarris Avatar answered Sep 28 '22 23:09

Simon Sarris