开发者

Clearing canvas causes the old content to re-appear on the next draw

开发者 https://www.devze.com 2023-02-13 06:24 出处:网络
I have a clear button which seem开发者_开发百科s to work..but actually its not. When I click back on the canvas I can see the drawing.There is no problem in the way you are clearing the canvas, the pr

I have a clear button which seem开发者_开发百科s to work..but actually its not. When I click back on the canvas I can see the drawing.


There is no problem in the way you are clearing the canvas, the problem lies in your logic.

Everytime you click or move the mouse the addClick method is called, which populates the arrays clickX, clickY and clickDrag with the coordinates; and then the redraw method is called which plots the points on the canvas.

So when you clear the canvas you are failing to reset these arrays, so when the redraw method is called again (after clearing the canvas), the old points get plotted too.

So try emptying the arrays clickX, clickY and clickDrag as shown below, when you clear your canvas; so that the old points are not considered when you start fresh.

clickX = [];
clickY = [];
clickDrag = [];
0

精彩评论

暂无评论...
验证码 换一张
取 消