I have a problem with HTML 5 Canvas. I want to do kind of "versioning". So I want to be able to draw several lines with canvas. But then with a button I want to be able to delete as many drawn lines as possible. Is there a possiblity to do that? Thanks vor helping
Asked
Active
Viewed 132 times
0
-
Are you talkling about a drawing application or what's the purpose of those lines? Can you share your code? – obscure Jun 21 '19 at 14:47
-
If it's only several, you could consider transparent overlayed canvases, but otherwise, drawing on canvas is a permanent marker--you can draw over it or erase portions, but there's no undo or layers. More details about your actual use case would be helpful--if it's only "several", multiple canvases is probably workable, but if "several" means 500, you might need a different approach, probably involving redrawing the whole canvas from history line by line. – ggorlen Jun 21 '19 at 14:47
-
I yet do not have any code. What I was thinking of was to undo objects. – Sarah Xoxo Jun 21 '19 at 14:48
-
Possible duplicate of [HTML5 Remove previous drawn object in canvas](https://stackoverflow.com/questions/16969787/html5-remove-previous-drawn-object-in-canvas) – ggorlen Jun 21 '19 at 14:50
-
Also see https://stackoverflow.com/questions/7365436/ https://stackoverflow.com/questions/25819684/ https://stackoverflow.com/questions/31297389/ – ggorlen Jun 21 '19 at 14:51
1 Answers
0
Keep an array of lines (maybe start/end points) and when you are drawing, loop through the array and draw all the lines.

Marc
- 106
- 1
- 4