progressive alpha

Posted By: Marky Mark

progressive alpha - 07/15/06 00:25

how to do a model appear progressivly? I have a model and I want it to take 30 sec before reaching 100 of alpha... how to do this?
Posted By: ulillillia

Re: progressive alpha - 07/15/06 00:34

Do something like this:

Code:

function super_slow_fadein()
{
var total_time = 0;

while(1)
{
total_time += time;
entity.alpha = 48000/total_time;
wait(1);
}
}



The 48000 comes from 30*16*100 as there are 16 ticks in one second and alpha is from 0 to 100.

Edit: fixed a mistake I had (not 480, 48,000).
Posted By: Marky Mark

Re: progressive alpha - 07/15/06 00:37

thanks, but what will do the total_time var in this code?
Posted By: ulillillia

Re: progressive alpha - 07/15/06 00:39

total_time adds up the time each frame. At 16, that's 1 second. 1 second means an alpha of 3.333. I need to correct the code so it's 48000 instead (alpha isn't 0 to 1, but 0 to 100 and that's why). You know that 15 seconds is half of 30 and half transparent is 50%.
Posted By: Marky Mark

Re: progressive alpha - 07/15/06 00:51

I tried it like this:

Code:
 
function super_slow_fadein()
{
var total_time = 0;

while(1)
{
total_time += time;
my.alpha = 960/total_time; //480 = nb de sec * 16 tick in 1 sec
wait(1);
}
}

action formation {
super_slow_fadein();
}



I changed entity.alpha to my.alpha cause acknex got an error on running. I made this simple action, and attached it to my model.

Maybe its important to know that my model is a cloud, so I used alpha channels on many "frames" of the cloud.
Posted By: ulillillia

Re: progressive alpha - 07/15/06 00:59

30 seconds would use 48000 for that first number - it was a mistake that I made. 96000 would be one whole minute. Also, the while loop should have "while(my.alpha < 100)" instead. If you want this as an entity action, use this instead:

Code:

action super_slow_fadein()
{
my.skill1 = 0;

while(my.alpha < 100)
{
my.skill1 += time;
my.alpha = 96000/my.skill1;
wait(1);
}

my.alpha = 100; // full opacity is set only when while loop becomes false
}


Posted By: Marky Mark

Re: progressive alpha - 07/15/06 01:12

Aight I tried and nothing happens to my model. its staying at 100 of alpha. I tried puttin my.alpha=0; before the loop, but i still get no result
Posted By: ulillillia

Re: progressive alpha - 07/15/06 01:14

Did you, by chance, set the transparent flag? Add this as the first line within the action:

my.transparent = on;

Setting the alpha has no effect if the transparent flag is not on.
Posted By: Marky Mark

Re: progressive alpha - 07/15/06 01:15

-_- rofl shame on me.. lets try it
Posted By: Marky Mark

Re: progressive alpha - 07/15/06 01:16

Do I have to set my skill1 to something? (its not working :/ )
Posted By: ulillillia

Re: progressive alpha - 07/15/06 01:28

skill1 needs to be set to zero at the start. You won't get a divide by zero error because the time variable is being set to this and since it's not zero (unless your frame rate is above 16,384 fps, senselessly high)), you don't get the divide by zero error. Other than this, there shouldn't be any trouble. Keep in mind that the fade-in will be very slow so you'll need to wait a few seconds. Place the object on a background with maximum contrast (e.g. - white on black).

If that doesn't work, try setting the my.skill variable to some test value (I suggest 50,000, enough so it's noticable, for testing purposes only). If it's still not working, make sure the action is assigned to an entity and if you've added the entity through using WED, be sure you have rebuilt your level (especially to update entities).
Posted By: Marky Mark

Re: progressive alpha - 07/15/06 02:05

I tried all and its still not working... can you try it on a test level? maybe you'll see what's wrong?
Posted By: ulillillia

Re: progressive alpha - 07/15/06 13:02

I think I know. Set my.alpha = 0; at the start.

Code:

action super_slow_fadein()
{
my.skill1 = 0;
my.transparent = on;
my.alpha = 0;
wait(1); // first frame is completely invisible

while(my.alpha < 100)
{
my.skill1 += time;
my.alpha = 96000/my.skill1;
wait(1);
}

my.alpha = 100; // full opacity is set only when while loop becomes false
}



Another thing to note is whether or not your entity's skin is 32-bit or not. If the entity's skin is 32-bit color, with alpha at 50, it's fully opaque. If your entity's skin is 24 or 16-bit color, you shouldn't have this issue.
Posted By: Marky Mark

Re: progressive alpha - 07/16/06 05:08

hi,

Still no results, the entity is staying there totally visible...

I decided to returns it to a function, then get an action that tell the entity to be invisible at start. when I press F, the entity appears.

Code:
 
function formation()
{
my.skill1 = 0;
my.transparent = on;
my.alpha = 0;
wait(1); // first frame is completely invisible

while(my.alpha < 100)
{
my.skill1 += time;
my.alpha = 96000/my.skill1;
wait(1);
}

my.alpha = 100; // full opacity is set only when while loop becomes false
}

Action formation
{
my.transparent = on;
my.alpha = 0;
}

on_f = formation();



I'm getting this error when I press F:


Posted By: Xarthor

Re: progressive alpha - 07/16/06 09:23

Code:

function formation()
{
my.skill1 = 0;
my.transparent = on;
my.alpha = 0;
wait(1); // first frame is completely invisible

while(my.alpha < 100)
{
my.skill1 += time;
my.alpha = 96000/my.skill1;
wait(1);
}

my.alpha = 100; // full opacity is set only when while loop becomes false
}

Action formation_act
{
my.transparent = on;
my.alpha = 0;
while(me)
{
if(key_f)
{
while(key_f) { wait(1); }
formation();
}
wait(1);
}
}


Posted By: Marky Mark

Re: progressive alpha - 07/16/06 15:55

okAY no errors but no fade in... did you tried it? I placed a simple model in front of me when I start to test it...
Posted By: Marky Mark

Re: progressive alpha - 07/16/06 16:03

Quote:

okAY no errors but no fade in... did you tried it? I placed a simple model in front of me when I start to test it...




ok I just made an error... now at start its invisible and when I press F, it appears, but not progressivly.we're on the good way
Posted By: Excessus

Re: progressive alpha - 07/16/06 16:09

Uhm, the math error is pretty obvious..

Code:

while(my.alpha < 100)
{
my.skill1 += time_frame;
my.alpha = (my.skill1/(30*16)) * 100;
wait(1);
}


Explanation:
my.skill1 is the total time the loop has been running in ticks (1 tick = 1/16th of a second). 30*16 is the total time you want this loop to run in ticks. My.skill1/(30*16) gives the factor of how much of the time has been elapsed of the total time(0 when the loop starts, 1 when the loop is finished. We multiply this by the maximum alpha value we want (100..) to get the alpha value.
Posted By: Marky Mark

Re: progressive alpha - 07/16/06 16:51

its working! i love you guys

Excessus. txs for the explanation too
Posted By: ulillillia

Re: progressive alpha - 07/16/06 17:12

I checked and rechecked it and I don't see any error. Pretend 10 seconds have passed and the the span is 60. The alpha should be 16 2/3 which is 16.667. 10 seconds is 160 ticks. 96000/160 is... 600!? That's why it's not working! It should actually be this instead:

my.alpha = my.skill1/960;

I wonder why I didn't notice that . Plus, it's my.skill1 += time, not my.skill1 += time_frame. For 6.40.5 and later, it's my.skill1 += time_step.

This is the simpler version of it and it's faster as well than the method directly above.
Posted By: Excessus

Re: progressive alpha - 07/16/06 17:20

Quote:

it's my.skill1 += time, not my.skill1 += time_frame. For 6.40.5 and later, it's my.skill1 += time_step.




Well since 6.40.5 is the latest official release I write code for that version. time_frame is the correct variable here since we don't need the averaged value of time_step. In such a case where 'jerkyness' is not really an issue we should use the exact time of the last frame, thus time_frame, for precision.
Posted By: Marky Mark

Re: progressive alpha - 07/16/06 18:24

thanks
© 2023 lite-C Forums