Layer order

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.
Post Reply
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Layer order

Post by xNick1 »

Hi guys,
I have 3 things I want to draw.
I'm drawing them manually in the order I want to give them:

Code: Select all

function love.draw()
	sun:draw()
	mountain:draw()
	blackRectangle:draw()
end
The black rectangle has a high value on the alpha channel (love.graphics.setColor(0, 0, 0, 200)), that way the mountain is darker.
The problem is that I don't want that thing applied to the sun.

Obviously if I'd draw the things in the following way the sun would be bright, but the sun has to be behind the mountain!

Code: Select all

function love.draw()
	mountain:draw()
	blackRectangle:draw()
        sun:draw()
end
I'm sure that this is a very stupid issue and I'm missing something out o.O
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Layer order

Post by Nixola »

Code: Select all

function love.draw()
	lg.setColor(255, 255, 255)
	sun:draw()
	mountain:draw()
	blackRectangle:draw()
end
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Layer order

Post by Sir_Silver »

What Nixola has written seems like it would solve your issue!

I just wanted to chime in and say that I usually call setColor functions inside of my draw methods to avoid problems like this. (Assuming that this is a solution to the issue you're having)
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: Layer order

Post by xNick1 »

Nixola wrote: Tue Dec 12, 2017 2:55 pm

Code: Select all

function love.draw()
	lg.setColor(255, 255, 255)
	sun:draw()
	mountain:draw()
	blackRectangle:draw()
end
Black rectangle is being drawn on top of everything, and it draws something like setColor(0, 0, 0, 200), so the sun is still dark :/
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: Layer order

Post by xNick1 »

I'm attaching a .love file.
I draw everything, and then on top I put the filter to make everything darker.
Then I want only the player not to be affected by the dark thing
Attachments
attempt.love
(4.1 KiB) Downloaded 54 times
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Layer order

Post by Nixola »

Can't you draw the mountain with a darker color, instead of overlaying a transparent rectangle?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: Layer order

Post by xNick1 »

Yeah, it would solve the problem, but I would have to do that for every object but the sun.
It's 15 or more objects.
Drawing a whole rectangle affects the sun anyway and I can't think of any different solution.
I'll probably apply a lower alpha channel to every object then.

Thanks for the help guys
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: Layer order

Post by xNick1 »

Nixola wrote: Tue Dec 12, 2017 7:31 pm Can't you draw the mountain with a darker color, instead of overlaying a transparent rectangle?
I thought it would have worked if I applied the effect on every single object.
It didn't work either cause the sprite was something like 100x200 but the object doesn't fill every pixel. So I got dark areas around the mountain.
The black rectangle approach couldn't solve my problem and it was way too limiting hehe
So I used a shader instead.
I had to rewrite a lot of stuff but it looks way better now and I'm so satisfied with the result.
Posting a pic below:
received_10212971212746645.png
received_10212971212746645.png (65.23 KiB) Viewed 4437 times
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Re: Layer order

Post by Sasha264 »

xNick1, shader is good solution!
BTW, nice screenshot :cool:
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests