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 = [];
精彩评论