Page 1 of 2
Making a flashlight
Posted: Mon Nov 24, 2008 12:41 pm
by Kuromeku
Anybody know how this could be achieved?
So that everything is very dark except from where the flashlight beam is?
Re: Making a flashlight
Posted: Mon Nov 24, 2008 12:43 pm
by Kaze
Draw a flashlight beam(image?) under the zombies?
Re: Making a flashlight
Posted: Mon Nov 24, 2008 1:21 pm
by Kuromeku
I don't see how that would work? I want to zombies to be dark too unless the flashlight is over them.
Re: Making a flashlight
Posted: Mon Nov 24, 2008 3:31 pm
by evolve
Not sure how optimized this would be, but you could have a giant image for the flashlight, it would have to be 4 times the screen size, and have a transparent hole in the middle of it. Then move that, and make sure the zombies are drawn under that layer.
Re: Making a flashlight
Posted: Mon Nov 24, 2008 4:45 pm
by Kuromeku
Didn't think of that! Well done! Thanks.
Re: Making a flashlight
Posted: Mon Nov 24, 2008 4:47 pm
by surtic
Here's some code that does what I think you want:
Code: Select all
function load()
background = love.graphics.newImage("background.jpg")
flashlight = love.graphics.newImage("flashlight.png")
fw = flashlight:getWidth()
fh = flashlight:getHeight()
end
function draw()
local x, y = love.mouse.getPosition()
love.graphics.draws(background, x, y, x-fw/2, y-fh/2, fw, fh)
love.graphics.draw(flashlight, x, y)
end
Basically it draws just the rectangle under the flashlight, and then a flashlight mask on top of it.
Is that what you wanted?
Re: Making a flashlight
Posted: Mon Nov 24, 2008 5:00 pm
by Kuromeku
Oh my... that is perfect! Thank you very much!
I don't really understand how you achieved that though, I mean with the flashlight image?
Re: Making a flashlight
Posted: Mon Nov 24, 2008 5:05 pm
by Kaze
Kudomiku wrote:Oh my... that is perfect! Thank you very much!
I don't really understand how you achieved that though, I mean with the flashlight image?
The image is just black with a blurred hole(transparent) in the center
Re: Making a flashlight
Posted: Mon Nov 24, 2008 5:33 pm
by Kuromeku
How does it cut through the previous image though to make a hole? Pretty clever
Oh... it doesn't:
Code: Select all
love.graphics.draws(background, x, y, x-fw/2, y-fh/2, fw, fh)
Hmm... This is kind of what I need but, hmm.
Guess I could just use setScissor to the size of the flashlight image.
Re: Making a flashlight
Posted: Mon Nov 24, 2008 5:52 pm
by Kaze
Kudomiku wrote:How does it cut through the previous image though to make a hole? Pretty clever
Oh... it doesn't:
Code: Select all
love.graphics.draws(background, x, y, x-fw/2, y-fh/2, fw, fh)
Hmm... This is kind of what I need but, hmm.
Guess I could just use setScissor to the size of the flashlight image.
That or draw black around it. 4 rectangles)