In the game I am working on, I am trying to figure out the best way to handle "darkened" areas without drawing things redundantly and I was thinking the best way would to take the wall tiles, paste them onto a Canvas or into Image Data multiple times with each one being drawn slightly darker than the previous, then using the correct darkness image depending on the distance or light level. I would also need to preserve opacity.
Not sure how to go about it though. I guess PixelEffects would be a good idea, but not really sure how to really approach that.
Currently I was simply drawing the image once at 0,0,0 coloring (So they draw completely black) then again a second time with a slight opacity depending on the darkness. But this is redundant as it's causing extra draw calls. I figure if I pre-generate the different dark levels at load it would be so much better.
You my ask why I don't create the images beforehand. Well, I don't really feel like having to recreate each darkness every time I change a tile. That's just silly and wasteful.
I figure 10 light levels would be enough.
Take an image and make darker shades of it...
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Take an image and make darker shades of it...
I think the problem with any approach that applies the darkness level uniformly to an object is you don't get nice blending. If you are still working on the raycasting game, then that would be beyond me, but I remember an example of lighting that someone had in a .love file that might do the trick.
Here is it:
viewtopic.php?f=5&t=3622
Here is it:
viewtopic.php?f=5&t=3622
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Take an image and make darker shades of it...
No, all I need to do is take an image, create quads, darken its pixels by a certain amount, paste it into Image Data or a Canvas, create quads for the next darkness level, darken them again this time by 2 steps, paste them in, create the quads, repeat until completely dark.
It's easier. And that example has nothing to do with this. That's a completely different method for a completely different game type.
So basically, I just need code to take an image, manipulate its pixels, draw it to something that can be chopped up into Quads. Easy as pie.
It's easier. And that example has nothing to do with this. That's a completely different method for a completely different game type.
So basically, I just need code to take an image, manipulate its pixels, draw it to something that can be chopped up into Quads. Easy as pie.
Re: Take an image and make darker shades of it...
https://love2d.org/wiki/ImageData:mapPixel
The example talks about brightening an image, but you could change it to whatever.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Take an image and make darker shades of it...
I'm probably going about it completely wrong. Ignore this thread for now.
Re: Take an image and make darker shades of it...
Just drawing the images with a dark color would not work? I.e.:
Could you make an image of the effect you want to achieve?
Code: Select all
love.graphics.setColor(255 * lightness, 255 * lightness, 255 * lightness)
love.graphics.draw(img, x,y)
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Take an image and make darker shades of it...
No, that's exactly how I wanted to do it. And how I figured it out. But I was hoping I could make it so I could have images fading to different colors so I could use fog with white or red tint or green. But i created a separate thread for that.
Re: Take an image and make darker shades of it...
can't you just ;
copy imgdata to new framebuffer, set the color black and then use the alpha to control lighting levels,draw a poly over the tile, then use that to make quads from?
copy imgdata to new framebuffer, set the color black and then use the alpha to control lighting levels,draw a poly over the tile, then use that to make quads from?
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Take an image and make darker shades of it...
I would have to make quads for every single column of every single tile in every single color that I want to use.
With 64 pixel tiles, that's 64 quads per tile times number of tiles times number of colors.
Of course I could reuse the same quads, but then I'd need to make multiple canvases for each color instead. I'm already overusing canvases as it is.
With 64 pixel tiles, that's 64 quads per tile times number of tiles times number of colors.
Of course I could reuse the same quads, but then I'd need to make multiple canvases for each color instead. I'm already overusing canvases as it is.
Re: Take an image and make darker shades of it...
You can just do what vrld said but multiple times in one draw, right?Jasoco wrote:But I was hoping I could make it so I could have images fading to different colors so I could use fog with white or red tint or green.
Code: Select all
-- Image 1, red tint
love.graphics.setColor(255 * lightness, 180 * lightness, 180 * lightness)
love.graphics.draw(img1, x1,y1)
-- Image 2, green tint
love.graphics.setColor(180 * lightness, 255 * lightness, 180 * lightness)
love.graphics.draw(img2, x2,y2)
-- Image 3, blue tint
love.graphics.setColor(180 * lightness, 180 * lightness, 255 * lightness)
love.graphics.draw(img3, x3,y3)
Who is online
Users browsing this forum: No registered users and 1 guest