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.

I have a day cicle in my game. I want to add a bluish hue to my terrain in the early morning and evening-night. I want to start transitioning from 0 hue color to the full hue color at 20 PM and reach the full color at 0 AM, then start fading back and reach 0 hue color at 7 AM. red is the color, vertical is the color amount, horizontal is the time

Given a time of day in hour and minute, or seconds, how can I write a function to calculate the hue color correctly?

share|improve this question
    
If you want a somewhat more realistic formula, see e.g. "A Practical Analytic Model for Daylight" by Preetham, Shirley & Smits. –  Ilmari Karonen Jun 29 '13 at 21:32

1 Answer 1

It sounds like you want a simple implementation. So here's what you can do.

  • Pick your night-time hours. It sounds like you want 8pm to 7am (11 hours)
  • Pick your formula. Is it linear transitions all throughout, or is there a time of "constant" daylight? Let's assume you always want the time moving.
  • Experiment in an image editor. Take a screenshot of your game, overlay a blue layer, and see what the maximal transparency is that you want -- say 50%.

If you decide on these parameters (tweak to your liking), the rest is easy; you just need a formula for changing the alpha. It will start at 0 (8pm), and at 0 (7am), and peak at 50% (1:30am).

The formula should be pretty easy to calculate from this. You use the time difference from now to the peak time, and use that to swet the alpha of the blue overlay.

share|improve this answer

Your Answer

 
discard

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