views:

77

answers:

3

There's a way of implementing an eraser (other than using a white pencil?).

I'm using layering, I have an image below the canvas, so, if eraser paints white, the user is going to notice since the below image isn't solid white.

Thanx.

A: 

set the pencil color to transparent:

context.fillStyle = "rgba(255,0,0,0)";

in rgba() format, the last one is the alpha channel, 0 is totally transparent

Javier
It does't work. The 'eraser pencil' stills draw on red (the color of the actual drawing pencil).
Valentina
try setting the color as simply "transparent" (http://dev.w3.org/csswg/css3-color/#transparent), or maybe `strokestyle` instead of `fillstyle`
Javier
=( Nothing. I already tried both context.strokeStyle = "rgba(0,0,0,0)"; and context.fillStyle = "rgba(0,0,0,0)";. Any ideas?
Valentina
A: 

As an alternative, you can use multiple <canvas> objects drawn over each other, then erase from the top canvas to reveal the image beneath. See: html5 - canvas element - Multiple layers

ChessWhiz
+2  A: 

Basically, set the globalCompositeOperation to copy and paint using a color with opacity zero, e.g. "rgba(0,0,0,0)" as you were trying.

The question is answered in a bit more detail here:

http://stackoverflow.com/questions/3328906/erasing-in-html5-canvas

andrewmu