Multiple Canvas elements on same page or not?

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Multiple Canvas elements on same page or not?

Post by Verahta »

Context: a browser game written in HTML5/JS/Node, with multiple 'windows' or view-ports doing different things (say map, radar, vitals, etc).

Would you just make the entire game inside one canvas, or break up each "content area" into it's own canvas and structure the rest of the game UI like a web app/site?
"In order to understand recursion, one must first understand recursion".
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Multiple Canvas elements on same page or not?

Post by hallsofvallhalla »

hmm good question. Cant say i have a good answer for it. The one thing I would do is do a test on both. Check speed and data size to see if there is any difference. I would personally want to break them up but I would have concerns on if it adds to overhead.
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Re: Multiple Canvas elements on same page or not?

Post by Verahta »

Yeah, I'm not very experienced so I am struggling to grasp how to best structure everything together.

What about cross-platform availability? Would multiple canvases not work for a tablet app version of the game?
"In order to understand recursion, one must first understand recursion".
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Multiple Canvas elements on same page or not?

Post by a_bertrand »

Using only one canvas should give you better performances, but forces you to refresh every single piece every time one of the piece want to redraw. Yes you could also have partial redraws but usually this is even more complex. So it pretty much depends on your own game and how it works, even if personally I would tend to try to make only one canvas if possible.
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Re: Multiple Canvas elements on same page or not?

Post by Verahta »

GX-mockup-1.jpg
I threw together this quick and dirty mock-up to try and better explain what I mean. Obviously it's dumb and makes no sense, but it does illustrate basically the general idea of what I meant. A PBBG that can be played in the browser but also as an app on tablets.
"In order to understand recursion, one must first understand recursion".
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Multiple Canvas elements on same page or not?

Post by hallsofvallhalla »

I did some reading on this and agree with a_betrand. I however do not think having multiple will affect your performance enough to outweigh being able to draw each one differently.
I personally would recommend multiple canvas's.

good article
http://www.html5rocks.com/en/tutorials/ ... mul-canvas
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Re: Multiple Canvas elements on same page or not?

Post by Verahta »

Sounds like it is definitely a legitimate option.

http://www.ibm.com/developerworks/libra ... index.html
"In order to understand recursion, one must first understand recursion".
Post Reply

Return to “General Development”