Live data from Hacker News

Why Canvas is not an obvious choice for web games

paulbakaus.com

21–25 of 25 posts

Re: Why Canvas is not an obvious choice for web games

#21

I'm with this guy. Canvas is great, but it's an element to include in your scene to render vector graphics, not a container for you to render your scene inside. Often you'll have dozens of them layered about the place, happily doing their thing and unaware of each other. Use it right and it's a great tool. Try to use it as a panacea Flash replacement and you're in for a bunch of headache.

Apologies for going Meta, but the above downvote is the strangest one I've yet seen here. I can't come up with a way to read my comment as inflamatory or "me too". The only thing I can guess is that it's a downvote for disagreement, but without any commentary I can't imagine why the downvoter would do so. It seems like the kind of thing one could easily refute with evidence, if one had evidence that it was incorrect.

I didn't downvote you, and I've spent enough time on reddit to stop questioning downvotes because they are too stochastic to spend braincell-seconds trying to interpret. But when I read your comment I immediately questioned why you would call canvas best suited for rendering vector graphics. If anything, VML/SVG via something like Raphael.js is best suited for that, because you can use graphics data exportable from a vector graphics editor like Illustrator, and manipulate the data in your page in a structured way--Raphael somewhat mitigates the painfulness of DOM operations.

I would say canvas is best suited for rendering/processing sprite or pixel-based graphics that does not need mouse interaction, if I had to pigeonhole it. Sure, I've used it via Flot to draw charts, and for purposes that were decidedly vector-ish, but I would never expect to be able to manipulate that stuff without complicated collision data and redraw logic. The API for drawing with the canvas pen is moderately featured but drawing imperatively and trying to act on -mouse interaction just isn't scalable or maintainable.

Re: Why Canvas is not an obvious choice for web games

#22

I think he is comparing apples to oranges here. Using HTMl as the "rendering device" works on a different (higher) level of abstraction. The additional layer of abstraction in HTML has already solved the complexity of doing efficient partial redraws based on changes to a subset of a scene graph. This isn't something that the canvas API was meant to handle. If one were to use a scene graph (or display list) abstractio…

> Basically, what he needs is SVG. :-) Yes. It's incredibly frustrating that we can't rely on embedding SVG in HTML. (Last I looked--about 2.5 years ago, admittedly--only Firefox could do it, and only with XHTML.)

You should check out http://raphaeljs.com/ , which basically unifies the SVG API in a cross-browser way. In IE, it translates everything to VML on the fly. You need to transcode your SVG to Raphael's JSON-based format, but it's not hard to do.

Re: Why Canvas is not an obvious choice for web games

#23
post #17

Earlier quoted context omitted.

I agree that it is a right tool for the job type of situation but I think there are many times when canvas is that tool for certain types of games. I understand the complexity of the Aves engine and what they are trying to do - but their performance needs are greater than most of the other games out there. I think for simple tile-based games (pac man, mario bros, bejeweled) and casual 2d games (side scrolling shooter…

Really? Why would you bother with Canvas at all if you were doing anything (non-rotating) sprite-based? Canvas' main advantage is that it can render vector graphics. Beyond that it's useful for doing image rotation in a cross-platform way and for manipulating bitmaps. If your game doesn't require those things, I can't think of a reason you'd want to use it in favor of something the browser is so natively good at as l…

canvas is for raster graphics, not vector...

Re: Why Canvas is not an obvious choice for web games

#24

Earlier quoted context omitted.

> Basically, what he needs is SVG. :-) Yes. It's incredibly frustrating that we can't rely on embedding SVG in HTML. (Last I looked--about 2.5 years ago, admittedly--only Firefox could do it, and only with XHTML.)

Once IE 9 comes out, the majority of browsers will support inline SVG. Only Opera is currently an unknown: http://caniuse.com/#cats=SVG,Summary&statuses=rec,pr,cr,...

Thanks!

Re: Why Canvas is not an obvious choice for web games

#25
post #22

Earlier quoted context omitted.

> Basically, what he needs is SVG. :-) Yes. It's incredibly frustrating that we can't rely on embedding SVG in HTML. (Last I looked--about 2.5 years ago, admittedly--only Firefox could do it, and only with XHTML.)

You should check out http://raphaeljs.com/ , which basically unifies the SVG API in a cross-browser way. In IE, it translates everything to VML on the fly. You need to transcode your SVG to Raphael's JSON-based format, but it's not hard to do.

Thanks, I'll take a look next time I need it.
Post reply on HN