Page 1 of 1

Night effect

Posted: Thu Jun 12, 2014 1:58 am
by pielago
I am confuse about night effect!
Do i need to create a new layer or something and does alpha work with it?
or how does it works?
To turn the day in to night????

hope someone can give me an easy example or something to understand

thank you!!

Re: Night effect

Posted: Thu Jun 12, 2014 2:53 am
by HugoBDesigner
What are you dealing with? Images? Colored backgrounds? Be more specific, please... I could help with both, but you need to give us more information. For both cases, though, this could help:

Code: Select all

function fade(currenttime, maxtime, c1, c2)
   local tp = currenttime/maxtime
   local ret = {} --return color
   
   for i = 1, #c1 do
      ret[i] = c1[i]+(c2[i]-c1[i])*tp
      ret[i] = math.max(ret[i], 0)
      ret[i] = math.min(ret[i], 255)
   end
   
   return unpack(ret)
end

Re: Night effect

Posted: Thu Jun 12, 2014 8:41 am
by pielago
i was just wondering example..
if i do a small game Zelda style and want the night and the day
what will be the best way to do it... i am looking for the easiest and best way possible..
image ,color etc any ideas.. like a example a tutorial example...

Re: Night effect

Posted: Thu Jun 12, 2014 3:31 pm
by DrCicero
Well, what is the difference between night and day in real life? :rofl: The light/shadow. Typically at nighttime there is less light and so everything is darker. So simple draw a black rectangle over the screen, while changing the alpha value according to the time:

Code: Select all

love.graphics.setColor(0,0,0, (sin(love.timer.getTime() / 1000)/2+1)*255)
love.graphics.rectangle(0,0,love.window.getWidth(),love.window.getHeight())
(The '/1000' is the factor you need to change if you want a quicker/slower day-night cycle.)

Another visual indicator for a day/night cylce is a clock on the screen, or for example street lamps which are depending on the time lit or not (have a sprite for the lit street lamp and one for the normal one and change them in time).

Please note that not many games have a day/night-cycle, because it does not add anything to the game. So if you don't intend to add anything that is different between day and night and affects the gameplay (certain events only happening at a specific time, or having soldiers guard the city at night, or having monsters wander the forest only at night, ...) you should consider not implementing day/night cycle.

So please think about gameplay things that would change and are fun besides the implementation. :cool:
(But if your goal is not really gameplay but maybe graphics or something different your opinion may vary. ;) )

Re: Night effect

Posted: Thu Jun 12, 2014 6:40 pm
by Ref
You could also create two images (day & night) and use a shader to morph between them.

Re: Night effect

Posted: Thu Jun 12, 2014 8:03 pm
by gestaltist
A very basic way to do it (looks OK, not great, but is trivial to implement) is to draw a black rectangle over the whole screen - but with very low opacity (alpha channel), that slowly rises the darker it gets.

Re: Night effect

Posted: Thu Jun 12, 2014 8:05 pm
by Jasoco
Or a dark blue rectangle if you want it to be like moonlight. Dark red if you are in a hot or lava area. Whatever color fits at the time.

And you can do a flashlight effect if you look into the Subtract blend mode. (Or is it color mode? I always mix those up.) Where you draw a solid white shape of some sort on a solid white filled canvas using Subtract and it subtracts the pixels from the shape. You can do simple darkness effects with light sources this way. Think Link to the Past when in a dark dungeon and you have the lantern with you.

Edit: Here's an example of how I've done it in the past...
Screen Shot 2014-06-12 at 4.07.43 PM.png
Screen Shot 2014-06-12 at 4.07.43 PM.png (31.43 KiB) Viewed 4676 times
I use a canvas at the resolution of your drawing area, fill it in solid white, then use a template of one of a few pre-drawn light sources, in this case two mediums for the snakes, and a large for Mike, as well as special square ones for each lava tile and draw them all on the canvas using Subtract. This basically cuts those pixels out of the image by setting their opacity to 0. (255 opacity minus 255 opacity equals 0 opacity) Then I draw the white canvas to the screen using whatever color I want the light to be. I find it works better with solid 255 opaque or completely transparent (0 opaque) pixels. Anything in between with canvases doesn't look right. I haven't figured out if there's a way to do it without canvases yet. Also, since it uses canvases and only binary opacities it's best with games with a pixel-y art style. For other methods you can look into one of a few lighting libraries here.

Re: Night effect

Posted: Mon Jun 16, 2014 9:25 am
by pielago
i see...
I get it and don't lol .But one thing is for sure i can always count on you guys :) i will try and see
i don't understand the 2 pictures one night and the other one day??? so morph.lua works only with similar pictures
one darker and the other one lighter ? is it extra work??? or am i missing something????
great forum :)

Re: Night effect

Posted: Mon Jun 16, 2014 3:02 pm
by Ref
Play around with it!
All morph does is provide a way to smoothly transition from one image to another - very simple to use.