1
\$\begingroup\$

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?

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy