0

I need to draw a line that moves from left to right over the screen. Currently I'm just calling .clearRect() everytime, and draw it again, 1 pixel further. However, another possibility would be to draw the canvas once, and move it's CSS position across the screen.

Which scenario would be preferred for performance and why?

Maestro
  • 9,046
  • 15
  • 83
  • 116
  • 1
    As always, be sure you verify with your own performance tests, but css is probably going to be faster. See this comparison: http://stackoverflow.com/questions/4842872/performance-of-moving-image-on-web-page-via-css-vs-html5-canvas – markE May 22 '13 at 22:10

1 Answers1

0

Moving, or "transforming" is always going to be much faster.

You're on the right track, but this is already built into Canvas. Here's a link on how to accomplish this:

Canvas Transform Tutorial

Canvas Transform

Captain Skyhawk
  • 3,499
  • 2
  • 25
  • 39