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.
stout
Citizen
Posts: 64
Joined: Sun Oct 07, 2012 4:42 pm

Re: a way to overwrite a color

Post by stout »

rokit boy wrote: 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.

Code: Select all

alpha1 = 255


function love.draw()


	love.graphics.setBackgroundColor(255,255,255) -- set background color to white so we can see what we're doing

	love.graphics.setColor(0,255,0) -- green
	love.graphics.polygon('fill', 100, 100, 200, 100, 150, 200) -- draw a triangle
	
	love.graphics.setColor(0,0,0,alpha1) -- black, with a variable defined with our alpha (transparency)
	love.graphics.rectangle("fill",100,100,100,100) -- a square

	if viewBlock == 1 then
		love.graphics.setColor(255,0,0,50) -- red, with a little bit of alpha just for illustration; 0 = transparent
		love.graphics.rectangle("fill",100,100,100,100) -- a square
	end
end

function love.keypressed(key)
     -- press A or B to switch the block transparencies
	if key == "a" then
		alpha1 = 255
		viewBlock = 0
	end
	if key == "b" then
		alpha1 = 0
		viewBlock = 1
	end
end
I think this illustrates the effect you're going for, but I don't know if it's the way you want to do 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 »

Thanks for guiding me to stencils! it worked!
special thanks to boolshet on irc!
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 »

Thanks from my part too. I didn't know the Stencil functions.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 61 guests