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!!
Night effect
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: Night effect
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
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...
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
Well, what is the difference between night and day in real life? 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:
(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.
(But if your goal is not really gameplay but maybe graphics or something different your opinion may vary. )
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())
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.
(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)
Re: Night effect
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 222 times
-
- Prole
- Posts: 49
- Joined: Thu May 29, 2014 10:56 am
Re: Night effect
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.
--
My OOP implementation:
https://github.com/stefanstr/class-by-gestaltist.git
My dungeon / tiled map generator:
https://github.com/stefanstr/lua_maps_by_gestaltist
My Love2D experiments:
https://github.com/stefanstr/Small-Love2D-Projects
My OOP implementation:
https://github.com/stefanstr/class-by-gestaltist.git
My dungeon / tiled map generator:
https://github.com/stefanstr/lua_maps_by_gestaltist
My Love2D experiments:
https://github.com/stefanstr/Small-Love2D-Projects
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Night effect
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... 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.
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... 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
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
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
Play around with it!
All morph does is provide a way to smoothly transition from one image to another - very simple to use.
All morph does is provide a way to smoothly transition from one image to another - very simple to use.
Who is online
Users browsing this forum: No registered users and 3 guests