Author Topic: About fading objects in & out  (Read 308 times)  Share 

Pet Terry

  • Mittens Vassal
  • Sunshine.
    • I can help with AGS tutoring
    •  
  • Pet Terry worked on a game that was nominated for an AGS Award!
About fading objects in & out
« on: 17 Nov 2003, 16:23 »
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

  • I am Tom Selleck's Love Child.
Re:About fading objects in & out
« Reply #1 on: 17 Nov 2003, 16:36 »
Wouldn't this speed it up?

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

Re:About fading objects in & out
« Reply #2 on: 17 Nov 2003, 16:38 »
Yes , instead of counter++ , use counter+=2 , or counter+=3

Pet Terry

  • Mittens Vassal
  • Sunshine.
    • I can help with AGS tutoring
    •  
  • Pet Terry worked on a game that was nominated for an AGS Award!
Re:About fading objects in & out
« Reply #3 on: 17 Nov 2003, 16:42 »
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

  • Life is a laugh
    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re:About fading objects in & out
« Reply #4 on: 17 Nov 2003, 19:40 »
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
}
}

:)
« Last Edit: 17 Nov 2003, 20:00 by GinnyW »
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

Re:About fading objects in & out
« Reply #5 on: 19 Nov 2003, 09:08 »
Nice, but a bit risky as is ;)
If rate doesn't divide 100, then you'll overshoot the test values.

Modified version.
[code]
// 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.
}
}[/code]
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.
« Last Edit: 19 Nov 2003, 09:33 by After »

Ginny

  • Life is a laugh
    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re:About fading objects in & out
« Reply #6 on: 19 Nov 2003, 12:11 »
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