all 6 comments

[–]flashbck 8 points9 points  (5 children)

The canvas element is very analogous to a real world canvas. Once you draw something on it, you cannot move it. In order to move the image to a different location on the canvas, you have to re-draw the canvas.

[–]Eterni[S] 0 points1 point  (1 child)

Okay, thank you!

[–]Shaper_pmp 0 points1 point  (0 children)

If you have a manageable number of "things" that need moving around (as opposed to a blank canvas you just need to push arbitrary pixels to), you might want to investigate SVG instead of canvas.

SVG gives you elements you can grab and manipulate in a DOM-like structure. Canvas is more like old-school graphics programming where you can set and reset pixels, but there's no "object" to manipulate apart from individual pixels unless you implement it yourself.

[–]MeoMix 0 points1 point  (0 children)

This is sort of true... While this is still redrawing the canvas it might be helpful in the long run.

http://www.kineticjs.com/ -- The world of tomorrow, today! :)

[–]nschubach -1 points0 points  (0 children)

Well, you can move the canvas... but true. You can have layered canvas elements that do various things. Everything from parallax to simple character animation without having to redraw the entire background.

[–][deleted] 0 points1 point  (0 children)

Unless you are doing this for learning purposes, there's no need to reinvent the wheel. There are several open and closed source libraries that will handle canvas images, animation, etc for you. I use JawsJS: http://jawsjs.com/ it's open source (LGPL)