I read one article on html5 canvas. This is drawing with lines. So when adding each new line, the author clears the canvas and re-draws all the previous ones. And this makes sense if you want to undo actions or layers. But wouldn't it be better to do the drawing completely over again only in cases when you really need it?

I have never taken up the schedule and do not know how stupid this question is and whether there is any sense in this method. Please explain.

    1 answer 1

    Perhaps due to the fact that in most tasks, the background usually needs to be cleaned up (even if most of the canvas remains unchanged, it is still much easier than figuring out what has changed).

    This, of course, is unnecessary work, but in general, if it takes longer to draw the entire frame than it takes between frames, it is better to optimize in the drawing itself (it can, for example, cache complex groups into bitmaps and output them already), rather than save on redrawn areas . In any situation, you will need to draw everything at once (at least in the first frame) and the page will freeze.

    • But if my task is to trite to draw (with a pencil and an eraser), albeit in different colors and sizes, without the ability to cancel or anything else? - StormWhisper
    • And then, yes, it will be clearly unnecessary to clean. - Surfin Bird