day/night cycle using canvas

Non-platform specific questions.

Re: day/night cycle using canvas

Postby master0500 » Mon Jul 09, 2012 7:01 am

could you explain the code and how it works? and what actor does it go with?
master0500
 
Posts: 409
Joined: Sun Jun 26, 2011 9:42 pm
Score: 27 Give a positive score

Re: day/night cycle using canvas

Postby skydereign » Mon Jul 09, 2012 9:04 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: day/night cycle using canvas

Postby master0500 » Mon Jul 09, 2012 10:43 am

it doesn't do anything
master0500
 
Posts: 409
Joined: Sun Jun 26, 2011 9:42 pm
Score: 27 Give a positive score

Re: day/night cycle using canvas

Postby skydereign » Mon Jul 09, 2012 6:10 pm

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.
Attachments
sun.ged
(3.41 KiB) Downloaded 87 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest