Re: day/night cycle using canvas

Posted:
Mon Jul 09, 2012 7:01 am
by master0500
could you explain the code and how it works? and what actor does it go with?
Re: day/night cycle using canvas

Posted:
Mon Jul 09, 2012 9:04 am
by skydereign
- Code: Select all
double ang = (int)abs(90-sun_angle)%360;
if(ang>180.0)
{
ang = 360.0-ang;
}
transp = 1.0-(ang/180.0)*0.7;
All this code is doing is finding the closest difference between the angle of the sun and 90 degrees. Just dry run a few angles and it should be pretty clear how it does that. This makes the max distance from 90 degrees 180 degrees (which would be max darkness). ang/180 yields a percent darkness. If ang/180 is 0, that means transp is equal to 1, and it is fully bright. If ang/180 is 1 (max darkness), transp is set to 0.3. Using the percent like this is similar to how you do rotation with animpos. Knowing that, it is pretty obvious this code goes with the black overlay actor, as it is the one with the transp changing. But it is easy enough to switch, as long as you specify the actor.transp.
Re: day/night cycle using canvas

Posted:
Mon Jul 09, 2012 6:10 pm
by skydereign
Yes it does. If you just copied my code, you might not have implemented it correctly, but the point wasn't to copy it. I'm assuming you don't really understand how it works, otherwise it should be pretty clear that it works. I'm guessing you didn't actually implement the rotating sun (or the variable equivalent). Regardless, here is a ged showing it work. I used a canvas in this, since I didn't want to have to post the data, but the canvas actor would be replaced by your black overlay actor.