How to clean a canvas area?

Asked

Viewed 6,917 times

10

I created a function that generates random objects in the area canvas and wanted that after the end of this function the area was clean.

Is there any possibility of doing that?

2 answers

10


  • Thank you @Gabriel! [OFF TOPIC] You know if there is a possibility to add events to my elements within the canvas?

  • 1

    @Odair Take a look at this article at the bottom of the page: http://diveintohtml5.com.br/canvas.html. Here’s how to play a little game with canvas by adding events, etc.

  • Valeu @Gabriel!

2

context.clearRect(A, B, C, D);

A: point on the x-axis where cleaning will start.

B: point on the y-axis where cleaning will start.

C: Limit on X-axis to be cleaned.

D: Limit on the y-axis to be cleaned.

context.clearRect(0, 0, canvas.width, canvas.height);

Note: This way you will clean from the point X = 0 and Y = 0, until the end of your canvas, that is canvas.width and canvas.height.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.