a way to overwrite a color

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

a way to overwrite a color

Post 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?
u wot m8
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: a way to overwrite a color

Post 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?
When I write def I mean function.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: a way to overwrite a color

Post 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.
u wot m8
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: a way to overwrite a color

Post 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.
Help us help you: attach a .love.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: a way to overwrite a color

Post by rokit boy »

i think it's called masking, and i know it's possible with canvases but i don't support them.
u wot m8
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: a way to overwrite a color

Post 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.
When I write def I mean function.
stout
Citizen
Posts: 64
Joined: Sun Oct 07, 2012 4:42 pm

Re: a way to overwrite a color

Post 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.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: a way to overwrite a color

Post 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.
u wot m8
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: a way to overwrite a color

Post by Nixola »

I think you may be looking for Stencils
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: a way to overwrite a color

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 69 guests