Jump to content
  • Advertisement
Sign in to follow this  
MrDarkKnight

how to make day and night effect in sfml

This topic is 2536 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

[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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!