Page 1 of 2

a way to overwrite a color

Posted: Tue Oct 30, 2012 5:00 pm
by rokit boy
for example if i have a black square and i want to overwrite it with a transparent square i'll see whatever is behind that black square.
Is this possible?

Re: a way to overwrite a color

Posted: Tue Oct 30, 2012 5:13 pm
by kikito
What do you mean by "I have a black square"? Is it in LÖVE, or in a graphics editor? Is it an image or a rectangle drawn as a primitive?

Re: a way to overwrite a color

Posted: Tue Oct 30, 2012 5:32 pm
by rokit boy
kikito wrote:What do you mean by "I have a black square"? Is it in LÖVE, or in a graphics editor? Is it an image or a rectangle drawn as a primitive?
in love i draw a black square, then i draw another transparent square on top, i wanna be able to make it so it overwrites it which will make that space transparent.

Re: a way to overwrite a color

Posted: Tue Oct 30, 2012 6:23 pm
by Robin
You need to do something else. The information "behind" a pixel is not stored, so you need to make things transparent before you draw them. Can't be more specific unless you are more specific about what you are trying to do.

Re: a way to overwrite a color

Posted: Tue Oct 30, 2012 6:33 pm
by rokit boy
i think it's called masking, and i know it's possible with canvases but i don't support them.

Re: a way to overwrite a color

Posted: Tue Oct 30, 2012 7:06 pm
by kikito
rokit boy wrote: in love i draw a black square, then i draw another transparent square on top, i wanna be able to make it so it overwrites it which will make that space transparent.
The only way to do that in LÖVE is remembering what was "under" the black square and drawing that on top of it. You can't "make it transparent" because LÖVE doesn't automatically remember that.
rokit boy wrote:i think it's called masking, and i know it's possible with canvases but i don't support them.
I have never heard of "masking canvases". I'm not even sure they can be made transparent (can they?). In any case they are out of your reach, so it doesn't matter for your question.

Re: a way to overwrite a color

Posted: Tue Oct 30, 2012 8:10 pm
by stout
Can you describe what effect you're trying to achieve? We might be able to better understand it. Are you trying to do something like an x-ray view?

Code: Select all

function love.draw()
	love.graphics.setColor(255,0,0) -- set the drawing color to red
	love.graphics.rectangle("fill",100,100,100,100) -- draw a square (red)
	love.graphics.setColor(0,0,0,0) -- set the color to black, but make it 100% transparent 
	love.graphics.rectangle("fill",100,100,100,100) -- draw a square in the same spot (black/transparent)
end
This draws a red square, and a transparent square on top. You can test it by changing the fourth 0 in the second setColor to different values; if you set it to 255 instead you'll "see" a black square. This works because of drawing orders; the newest thing is always drawn "on top", but the things behind it are still being drawn as well.

But I have a feeling this isn't what you want. If you can give an example, or even an MS Paint diagram, it would help. =)

EDIT: Thinking about it some more, maybe you just want to do something like the code above, expointing the draw order, except turn off the black square when something happens. There's really no need to draw a transparent square on top of it.

Re: a way to overwrite a color

Posted: Tue Oct 30, 2012 9:05 pm
by rokit boy
stout wrote:Can you describe what effect you're trying to achieve? We might be able to better understand it. Are you trying to do something like an x-ray view?

Code: Select all

function love.draw()
	love.graphics.setColor(255,0,0) -- set the drawing color to red
	love.graphics.rectangle("fill",100,100,100,100) -- draw a square (red)
	love.graphics.setColor(0,0,0,0) -- set the color to black, but make it 100% transparent 
	love.graphics.rectangle("fill",100,100,100,100) -- draw a square in the same spot (black/transparent)
end
This draws a red square, and a transparent square on top. You can test it by changing the fourth 0 in the second setColor to different values; if you set it to 255 instead you'll "see" a black square. This works because of drawing orders; the newest thing is always drawn "on top", but the things behind it are still being drawn as well.

But I have a feeling this isn't what you want. If you can give an example, or even an MS Paint diagram, it would help. =)

EDIT: Thinking about it some more, maybe you just want to do something like the code above, expointing the draw order, except turn off the black square when something happens. There's really no need to draw a transparent square on top of it.
What i am trying to achive is that when i draw the transparent square (the black one) over the red one, it'll make it so you cant see the red one, but see the background.

Re: a way to overwrite a color

Posted: Tue Oct 30, 2012 9:25 pm
by Nixola
I think you may be looking for Stencils

Re: a way to overwrite a color

Posted: Tue Oct 30, 2012 10:11 pm
by Xgoff
not easily, since as mentioned, once you draw something you lose information about what was under it

you would basically have to use a stencil to define the erased area (only for that specific shape, though) and redraw everything.