About fading objects in & out

Started by Pet Terry, Mon 17/11/2003 16:23:10

Previous topic - Next topic

Pet Terry

Hello.

I've been using this code to fade objects and characters in and out:

Quote
ObjectOn(0);
while (counter<100) {
SetObjectTransparency(0,100-counter);
Wait(1);
counter++;
}

But is there a way to make objects and characters to fade faster? Because I think I saw it in some game... or?
<SSH> heavy pettering
Screen 7

Squinky

Wouldn't this speed it up?

ObjectOn(0);
while (counter<100) {
SetObjectTransparency(0,100-counter);
Wait(1);
counter=+2;
}

Spyros

Yes , instead of counter++ , use counter+=2 , or counter+=3

Pet Terry

Oh yes, thanks guys. I thought it would be possible with that line but didn't know what to do with it :P
<SSH> heavy pettering
Screen 7

Ginny

#4
I made a function a while ago for fading objects in and out, here it is if anyone is interested:

function FadeObjectIn(int objnum, int speed, int rate) {
// objectnum - object to fade in
// speed - 1 = fastest, 5 = slowest
// rate (transparency) - 1 = slower, 20 = faster, 100 = immediate

int trans = 100; // object initially invisible

while (trans != 0) { // as long as object hasn't fully faded in
SetObjectTransparency(objnum, trans); // change the object's transparency
trans = trans-rate; // subtract from transparency percentage
Wait(speed); // short pause, speed
}
}

function FadeObjectOut(int objnum, int speed, int rate) {
// objectnum - object to fade in
// speed - 1 = fastest, 5 = slowest
// rate (transparency) - 1 = slower, 20 = faster, 100 = immediate

int trans = 0; // object initially visible

while (trans != 100) { // as long as object hasn't fully faded out
SetObjectTransparency(objnum, trans); // change the object's transparency
trans = trans+rate; // add to transparency percentage
Wait(speed); // short pause, speed
}
}

:)
Try Not to Breathe - coming sooner or later!

We may have years, we may have hours, but sooner or later, we push up flowers. - Membrillo, Grim Fandango coroner

After

#5
Nice, but a bit risky as is ;)
If rate doesn't divide 100, then you'll overshoot the test values.

Modified version.
Code: ags

// objectnum, object to fade in or out.
// antispeed , 1 = fastest, 5 = slowest
// rate (transparency), 1 = slower, 20 = faster, 100 = immediate

function FadeObjectIn(int objnum, int speed, int rate) {
int trans = 100; // object initially invisible
while (trans > 0) { // as long as object hasn't fully faded in
trans = trans-rate; // subtract from transparency percentage
if(trans<0){trans=0;}//guarantee exact at finish.
SetObjectTransparency(objnum, trans); // change the object's transparency
Wait(antispeed); // pause.
}
}

function FadeObjectOut(int objnum, int speed, int rate) {
int trans = 0; // object initially visible
while (trans < 100) { // as long as object hasn't fully faded out
trans = trans+rate; // subtract from transparency percentage
if(trans>100){trans=100;}//guarantee exact at finish.
SetObjectTransparency(objnum, trans); // change the object's transparency
Wait(antispeed); // pause.
}
}

This assumes that the object transparency is already set at the initial value. e.g. Whatever is to fade out is fully opaque (0% transparent) before the function is called.

Ginny

Wow, thanks, I hadn't thought of the possibility that the transparancy would be set as a negatiove number with jumpps of 40 for example. I have thoughtof taking out the SetObjectTransparancy(objnum,0); so that objects can be transparent and still dafe out more, or vice versa. Thanks for editing :)
Try Not to Breathe - coming sooner or later!

We may have years, we may have hours, but sooner or later, we push up flowers. - Membrillo, Grim Fandango coroner

SMF spam blocked by CleanTalk