Night effect

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.
Post Reply
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Night effect

Post 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!!
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: Night effect

Post 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
@HugoBDesigner - Twitter
HugoBDesigner - Blog
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: Night effect

Post 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...
User avatar
DrCicero
Prole
Posts: 19
Joined: Sun Jun 01, 2014 8:56 pm
Location: Germany

Re: Night effect

Post 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. ;) )
Xeldas Saga - my ca. 10min action-platformer (contains sound effects, music, graphics and a boss fight)
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Night effect

Post by Ref »

You could also create two images (day & night) and use a shader to morph between them.
Attachments
day_and_night.love
morphing between two images
(111.06 KiB) Downloaded 207 times
gestaltist
Prole
Posts: 49
Joined: Thu May 29, 2014 10:56 am

Re: Night effect

Post 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.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Night effect

Post 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 4456 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.
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: Night effect

Post 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 :)
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Night effect

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

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 6 guests