Author: beffy (c++programmer)

NOTE: Due to the overlay on the entire screen and the excessive use of timers this may affect your framerate, so if you plan to constantly use the effect, you should come up with a more effective solution!!! Furthermore, it isn't a totally realistic effect, ideally you would move sun and moon, change the sky, stuff like that... ;-) Anyhow, it's pretty cool... :-) - First of all, read Melv May's resource and compile your engine with the provided guiFilter.cc (or get the file here). - Second, go to the gui editor (F10) and add a new GuiFilter control, set the sizes to relative (or copy this code into your playGui.cs:)
  

   new GuiFilter(nightFilter) {
      profile = "GuiDefaultProfile";
      horizSizing = "relative";
      vertSizing = "relative";
      position = "0 0";
      extent = "640 480";
      minExtent = "8 8";
      visible = "0";
      helpTag = "0";
      FilterColor = "0.000 0.000 0.000 0.000";
      MaskRed = "1";
      MaskGreen = "1";
      MaskBlue = "1";
   };

 
- Then open playGui.cs and add the following vars at the beginning of the file:
  

$currDarkness = "0.000";
$maxDarkness = "0.480";
$incrDarknessDelay = "4000";
$decrDarknessDelay = "4000";
$dayTimeDuration = "20000";
$nightTimeDuration = "12000";

 
Of course you can adjust them as you wish! - Add the following line to PlayGui::onWake()
  

   $nightSchedule = schedule($dayTimeDuration,0,"turnOnNightFilter");

 
- Finally, add the following functions at the end of the file:
  

function turnOnNightFilter()
{
   echo("turnOnNightFilter() called!");
   nightFilter.setFilterMask(true,true,true);
   nightFilter.visible = "1";
   nightFilter.setFilterColor(0.000, 0.000, 0.000, 0.000);
   $darknessSchedule = schedule($incrDarknessDelay,0,"increaseDarkness");
   cancel($nightSchedule);
}

function increaseDarkness()
{
   echo("increaseDarkness() called!");
   %step = $maxDarkness / 60;//"0.008";
   echo("$currDarkness: " @ $currDarkness);
   if($currDarkness > $maxDarkness)
   {
      $currDarkness = $maxDarkness;
      cancel($darknessSchedule);
      error("Now it is deepest night... buhuh!");
      $darknessSchedule = schedule($nightTimeDuration,0,"decreaseDarkness");
      return;
   }
   $currDarkness += %step;
   nightFilter.setFilterColor(0.000,0.000,0.000,$currDarkness);
   $darknessSchedule = schedule($incrDarknessDelay,0,"increaseDarkness");
}
function decreaseDarkness()
{
   echo("decreaseDarkness() called!");
   %minDarkness = "0.008";
   %step = $maxDarkness / 60;
   echo("$currDarkness: " @ $currDarkness);
   if($currDarkness < %minDarkness)
   {
      $currDarkness = %minDarkness;
      nightFilter.visible = "0";
      error("Reached end of one cycle here! A new day is dawning... :-)!");
      cancel($darknessSchedule);
      $darknessSchedule = schedule($dayTimeDuration,0,"turnOnNightFilter");
      return;
   }
   $currDarkness -= %step;
   nightFilter.setFilterColor(0.000,0.000,0.000,$currDarkness);
   $darknessSchedule = schedule($decrDarknessDelay,0,"decreaseDarkness");
}

 
And that's all, folks! Now your level should constantly change "day and night"... Have fun!

Commenter - add your comment below
Be the first person to add comment to this page!
Add a Comment
name:
email: (optional)
URL: (optional)
comment:
 
Commenter v.0.82 by GreatNexus.com web site design and development