Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Off the back of this post in which I asked two questions and received one answer, which I accepted as a valid answer. I have decided to re-ask the outstanding question.

I have implemented light points with shadow casting as shown here but I would like an overall map light with no point/light source.

The map setup is a top-down 2-d 50X50 pixel grid.

How would I go about implementing a day/night cycle lighting across a map?

share|improve this question
    
possible duplicate of How Do Day Night Cycles Work? –  Byte56 Oct 24 '12 at 13:21
    
I did search i think that post relates more to 3-d. but i'm sorry if its duplicated :( –  LoveofSnow Oct 24 '12 at 13:29
    
The concepts are the same. Changing the visuals of your game to represent more or less light. –  Byte56 Oct 24 '12 at 13:32

2 Answers 2

You should take a look into ambient lightning. This means you set a light color which is applied to all elements. This could be done in several ways. If you are using a shader for postprocessing you can add it there as a parameter and just change it to simulate day and night cycles.

A nice example was shown here (its in german, but maybe the source will help you a bit). It basically uses blend states to mix up different render targets containing the light sources.

share|improve this answer
up vote 0 down vote accepted

Thank you for your answer floAr I'm be up-voting your answer for giving me the term I was searching for:

Ambient lighting - lighting which is from no particular source but which is background lighting across all entities.

I've found this blog post with some very simple code which I'll be trying later.

this is the key for me:

new Color(ambientColor.R / 255f * ambient, ambientColor.G / 255f * ambient, ambientColor.B / 255f * ambient);

From the blog post:

(the approach is to modify the color of every sprite when drawing it)

Add to the top of your game class:

float ambient = 1f;  
Color ambientColor = Color.White;  

In the Update method:

KeyboardState c = Keyboard.GetState();  
if (c.IsKeyDown(Keys.Space))  
{  
   ambient -= 0.01f;  
   if (ambient <= 0)  
      ambient = 1f;  
}  

And finally, to apply ambient lighting to sprites:

Color drawColor = new Color(ambientColor.R / 255f * ambient, ambientColor.G / 255f * ambient, ambientColor.B / 255f * ambient); 
spriteBatch.Begin();  
spriteBatch.Draw(mySprite, new Vector2(0,0), drawColor);  
spriteBatch.End();

As you see, it's very easy :) With this, you could simulate for example day cycle.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.