Page 1 of 2
[SOLVED] Creating a dark fade (just forgot another "end")
Posted: Sun Oct 01, 2017 4:54 pm
by jdse03
.
Re: Creating a dark fade
Posted: Sun Oct 01, 2017 5:11 pm
by jdse03
.
Re: Creating a dark fade
Posted: Sun Oct 01, 2017 5:23 pm
by grump
I'm not quite sure what you mean by "weird jumps". Is the dark rectangle in the middle of your image supposed to cover the whole image? Can you show the image without the fade for comparison?
Doing this with setPixel is quite inefficient. setPixel is very slow.
This is a shorter and faster replacement for your nested loop:
Code: Select all
data:mapPixel(function(x, y, r, g, b, a)
return 0, 0, 0, math.min(y, maxAlpha)
end)
If you want to change the maxAlpha value on the fly, I'd recommend using a fragment shader instead of creating new textures.
Re: Creating a dark fade
Posted: Sun Oct 01, 2017 6:06 pm
by jdse03
.
Re: Creating a dark fade
Posted: Sun Oct 01, 2017 6:16 pm
by grump
jdse03 wrote: ↑Sun Oct 01, 2017 6:06 pm
I am only using setPixel when creating the image, which is at the start of the game, but thanks for the tip to improve performance.
It's not only about performance, but also about brevity. Why use complicated code when simple code does the same task, and faster to boot.
With "jumps" I mean the fact that it does not get darker but gets brighter/darker randomly when I want a smooth transition from bright to dark. On the first picture you can see how it gets darker first and suddenly gets brighter again for no reason.
You should show the code where you're drawing the fade image over the scene. And please, an image without the fade. It's not entirely clear from your image what is background and what is fade, at least not for me. I don't see the random jumps, but (and that's only a guess) it kinda looks like the fade is being drawn twice/mirror wrapped vertically around the center.
Re: Creating a dark fade
Posted: Sun Oct 01, 2017 7:14 pm
by jdse03
.
Re: Creating a dark fade
Posted: Sun Oct 01, 2017 8:25 pm
by zorg
Kinda looks like you're using a tile-based approach, and your issue may or may not be relevant to that; since from what i see, the brighter part starts just at the start of the lower row of "blocks"...
Re: Creating a dark fade
Posted: Sun Oct 01, 2017 8:30 pm
by jdse03
.
Re: Creating a dark fade
Posted: Sun Oct 01, 2017 9:02 pm
by jdse03
.
Re: Creating a dark fade
Posted: Sun Oct 01, 2017 9:14 pm
by grump
Have you tried drawing only the fade image over a white background to see what that looks like?
Or try to use a more visible image in place of the fade, that will help you understand what you're looking at. Like a colored grid or something.
However the used BlendMode "premultiplied" does not exist anymore.
BlendAlphaMode