Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

day and night?


Recommended Posts

current_hour is a variable that stores the current hour according to the computer's clock (in military time, i.e. hour 13 = 1 PM, 14 = 2 PM, etc...).

current_minute is the minute of the hour accourding to the computer's clock.

current_second is the second.

Using these variables, you arange to show a different background depending on what time it is.

For example if you want day to be from 6:00 AM to 6:00 PM and night to be the opposite:

if( current_hour >= 6 && current_hour < 18)
{
    background_index = bg_day;
} 
else
{
    background_index = bg_night;
}

You could make more complicated effects dealing with tints of the sky based on more precise times, but this is the jist of how it's done. Involving minutes and seconds could be a bit confusing, but if you want to get more elaborate, the functions under "GML->Computing Things->Dealing with dates and times" in the manual should simplify things.

Link to comment
Share on other sites

Ahh ok. I thought there was a chance it did since it uses D3D. But if anyone else needs a day/night pixel shader its very easy. Just by doing a linear interpolation between two images using the current time in the 0.0-1.0 range as the interpolation factor. Here is a HLSL Pixel shader for day/night transitions using the current time:

//The following 3 variables has to be set in the constant table(assuming you use D3D)!
float fTIme; // The current time in the 0.0-1.0 range
sampler2D dayMap;
sampler2D nightMap;

struct PS_INPUT
{
   float2 Texcoord : TEXCOORD0;
};

float4 ps_main(PS_INPUT Input) : COLOR0
{
   float4 dayColor = tex2D(dayMap,Input.Texcoord);
   float4 nightColor = tex2D(nightMap,Input.Texcoord);

   return lerp(dayColor,nightColor, fTime);
};

Link to comment
Share on other sites

In MMF, you just need to use the time object to modify the shade of your sprites, or animations, depending how your working with it. When time= noon, for instance, set Sonic to highest tone and backgrounds to animation "noon" after you make a darker and lighter tone based on the time , you'll need to recolor a lot os sprites, though, to fit times of day.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...