## Making a flashlight

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

### Making a flashlight

Anybody know how this could be achieved?

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

### Re: Making a flashlight

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

### Re: Making a flashlight

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

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

### Re: Making a flashlight

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

### Re: Making a flashlight

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

### Re: Making a flashlight

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

### Re: Making a flashlight

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

### Re: Making a flashlight

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

### Re: Making a flashlight

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)

### Who is online

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