how to make day and night effect in sfml

Started by
5 comments, last by MrDarkKnight 12 years, 3 months ago
Hello everyone

I have search all over Google trying to find how can i make a day and night effect in 2D and i could not find anything.

so how can i make my game looks like its night time and day time?
I'm using c++ and sfml.

thank you :)
Advertisement

Hello everyone

I have search all over Google trying to find how can i make a day and night effect in 2D and i could not find anything.

so how can i make my game looks like its night time and day time?
I'm using c++ and sfml.

thank you smile.png


For 2D games this is normally done by telling your artist to draw things that way.

If you want some type of dynamic light it gets quite a bit harder, you could probably just darken everything (either by reducing the color intensity in your images or by drawing a dark, semi opaque image over everything) but the results won't be great.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

[quote name='MrDarkKnight' timestamp='1326016670' post='4900593']
Hello everyone

I have search all over Google trying to find how can i make a day and night effect in 2D and i could not find anything.

so how can i make my game looks like its night time and day time?
I'm using c++ and sfml.

thank you smile.png


For 2D games this is normally done by telling your artist to draw things that way.

If you want some type of dynamic light it gets quite a bit harder, you could probably just darken everything (either by reducing the color intensity in your images or by drawing a dark, semi opaque image over everything) but the results won't be great.
[/quote]

ok thanks.
but if you look at this image you see the darkness in parts of the image, how can i make that?
dynamicshadows11.jpg

I know that the creator of this software is using dynamic lighting but i really don't care about that. i just want to be able to make things dark a bit.
SFML Sprites have a SetColor function. The default value is sf::Color(255, 255, 255, 255) but if you set it to 128,128,128,255 then it's drawn darker. For night though, you'd want something of blueish hue not pitch black.
If you just want to make an image a bit darker you could do as SimonForsman said and add a semi-transparent darker image over your screen or as Eigen said and change the colorvalue.

I think the problem with day / night cycle in 2D is that your sprites will most probably be drawn with a lightsource to them that wont apply during night time so I think the first thing SimonForsman said is the best alternative - have your artist draw one night and one day tileset.

If you want to create the effect of the sun rising / setting then I dont know smile.png

[size=2]*spelling

I know that the creator of this software is using dynamic lighting but i really don't care about that. i just want to be able to make things dark a bit.


If it doesn't have to be dynamic then you could just draw it as you want it, make a separate image where the completely dark parts are black and the light parts transparent and draw it over your level.

If you want things dynamic then you have to create this image at runtime (Exactly how this is best done depends on the game in question, the usual 3D methods such as volumetric shadows and shadowmapping could be adapted for 2D but may not perform well enough if done in software).

The image you linked is actually rendered using XNA (Which really is a 3D API):

You could read this:
http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/dynamic-2d-soft-shadows-r2032 which describes how to do it using OpenGL, and you should be able to adapt that to SFML
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
thank you very much guys that was helpful. :D

This topic is closed to new replies.

Advertisement