Hacker News new | ask | show | jobs
by jasonkester 5676 days ago
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.

2 comments

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 shooters, puzzle games, angry birds) canvas is a really easy way to go.

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 laying out image-based scenes.

These days, I'm much more inclined to use 3d-accererated CSS Transforms and Transitions first, then fall back on CSS positioning, then finally Canvas/SVG as a last resort for the few things that can't be accomplished by CSS/HTML.

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.

It wasn't me this time, but I've unfortunately downvoted plenty of good comments when using an iPhone (or similar touch based device). The two arrows are simply too close together for people using capacitive touchscreens and/or with fine motor control issues. If it's only one downvote I'd always bear in mind the possibility that it's due to fat-fingers, not your comment.
I still don't understand why HN doesn't allow users the opportunity to change a vote on reflection.
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 <canvas>-mouse interaction just isn't scalable or maintainable.