Making a flashlight

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
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Making a flashlight

Post by Kuromeku »

Anybody know how this could be achieved?

So that everything is very dark except from where the flashlight beam is?
User avatar
Kaze
Party member
Posts: 189
Joined: Sat Jul 19, 2008 4:39 pm
Location: Dublin, Ireland

Re: Making a flashlight

Post by Kaze »

Draw a flashlight beam(image?) under the zombies?
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Making a flashlight

Post by Kuromeku »

I don't see how that would work? I want to zombies to be dark too unless the flashlight is over them.
evolve
Prole
Posts: 5
Joined: Sat Nov 22, 2008 6:17 pm

Re: Making a flashlight

Post 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.
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Making a flashlight

Post by Kuromeku »

Didn't think of that! Well done! Thanks.
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Re: Making a flashlight

Post 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?
Attachments
flashlight.love
(115.83 KiB) Downloaded 277 times
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Making a flashlight

Post 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?
User avatar
Kaze
Party member
Posts: 189
Joined: Sat Jul 19, 2008 4:39 pm
Location: Dublin, Ireland

Re: Making a flashlight

Post 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
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Making a flashlight

Post by Kuromeku »

How does it cut through the previous image though to make a hole? Pretty clever :P

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.
User avatar
Kaze
Party member
Posts: 189
Joined: Sat Jul 19, 2008 4:39 pm
Location: Dublin, Ireland

Re: Making a flashlight

Post by Kaze »

Kudomiku wrote:How does it cut through the previous image though to make a hole? Pretty clever :P

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

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 42 guests