2

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?

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Vijeta Karani
  • 85
  • 1
  • 6

2 Answers2

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