I am taking text from user and displaying on canvas. Again if the user enters another text on the same position, then the text is getting overlapped and not replaced. How do I resolve this issue?
Asked
Active
Viewed 1,775 times
2
-
can you show an example? – kennypu Dec 31 '12 at 09:39
-
How much effort you put to debug this ? – Sahal Dec 31 '12 at 09:41
-
Possible duplicate of http://stackoverflow.com/questions/3543687/how-do-i-clear-text-from-the-canvas-element – Sahal Dec 31 '12 at 09:42
2 Answers
0
Use clearRect
and clear!
context.clearRect(0, 0, canvas.width, canvas.height);

Community
- 1
- 1

Praveen Kumar Purushothaman
- 164,888
- 24
- 203
- 252
0
Depends on how you are actually painting the scene on the canvas.
What you could do to clear that text is:
If you are tracking the elements drawn on the canvas (using objects and arrays), like how object-oriented canvas frameworks do, remove that object tracking the text. During the next redraw of the scene (or a partial), the text won't get drawn.
or, for a quick and easy way to do it, draw a rectangle over the text that matches the background. It's similar to placing correction fluid over ink on paper.

Joseph
- 117,725
- 30
- 181
- 234