Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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