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
  • 160,666
  • 24
  • 190
  • 242
Vijeta Karani
  • 87
  • 1
  • 6

2 Answers2

0

Use clearRect and clear!

context.clearRect(0, 0, canvas.width, canvas.height);
Community
  • 1
  • 1
Praveen Kumar Purushothaman
  • 160,666
  • 24
  • 190
  • 242
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
  • 113,089
  • 28
  • 177
  • 225