Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: luichy on Fri 28/11/2008 00:22:15

Title: Various Objects Fading In the same room [SOLVED]
Post by: luichy on Fri 28/11/2008 00:22:15
I want to make an intro with some text I made using a paint program. I want to make it appear one below the other with fade ins. Then after all the text has appeared one general fade out and continue to another cutscene in another room. There are a total of 5 text images I imported as sprites. How can I achieve that? Or is there a better workaround...

I've tried the manual, but I guess I'm still new to scripting, because it sometimes confuses me.

Thank you.
Title: Re: Various Objects Fading In the same room
Post by: on Fri 28/11/2008 00:37:43
It's not too hard- just go to the room for your intro and create an object for each text bit. Make sure you give each object a script name- like oText1 and so on. Objects can have their transparency set- a very good short example is in the manual under Objects.transparency. 100 means totally transparent, and 0 means solid. Basically it's


int i = 0;

while (oText1.transparency > 0) {
  oText1.transparency = i;
  i++;
  Wait(1);
}


It's just important to include the WAIT (because otherwise you won't see the fading) and to use the integer, since changing transparency directly does NOT work.

Obviously, since you have more than one text object, you will need to either set their transparency too (after my "text1...." example line), or to create different values and assign those.
Title: Re: Various Objects Fading In the same room
Post by: Trent R on Fri 28/11/2008 09:00:41
I'll also add that if you want it to fade faster, increase the value of i more i+=5; //Would make it 5 times faster To make it fade slower, increase the wait time (though 1++ and Wait(1) is slow enough, so don't increase the Wait).


~Trent


[Edit]:Instead of making a new post, editing this one.

If you use bigger numbers to change i (positive or negative) make sure you use the correct > < <= >= operators. If you have == 0 with i-=3, then it'll skip over it and crash.
Title: Re: Various Objects Fading In the same room
Post by: Dualnames on Fri 28/11/2008 09:08:45
Concerning of how fast it's done if you use numbers (instead of 5) like 3, or some other numbers it might crash your game, because you'd set a value of bigger than ..wait

Unless, I'm mistaken Ghost's code will increase the transparency forever, thus crashing the game
Shouldn't the code be more like:

int i[4] = 0;//increase array size(4) according to your object number
//initial otext1 transparency set 100//fully invisible
while (oText1.transparency != 0) {
  oText1.transparency = i[0];
  i[0]--;
  Wait(1);
}
//initial otext2 transparency set 100//fully invisible
while (oText2.transparency != 0) {
  oText2.transparency = i[1];
  i[1]--;
  Wait(1);
}
//ecc
//general fade out//
while (oText1.transparency != 100) {
  oText1.transparency = i[0];
  oText1.transparency = i[1];
//add more lines according to your obejcts
i[0]++;
i[1]++;
//add more lines according to your obejcts
  Wait(1);
}
Title: Re: Various Objects Fading In the same room
Post by: on Fri 28/11/2008 11:17:52
QuoteUnless, I'm mistaken Ghost's code will increase the transparency forever, thus crashing the game.
No, my example will work, because you can READ the transparency of an object easily.

Still, Dual's example will work too, and has the benefit of introducing an array. They're helpful if you handle more than one object.
Title: Re: Various Objects Fading In the same room
Post by: Trent R on Fri 28/11/2008 11:38:43
Ghost, shouldn't yours be <100? You have >0 along with ++ which should loop even when it's fully invisible...

~Trent
Title: Re: Various Objects Fading In the same room
Post by: on Fri 28/11/2008 12:02:12
Damnit! Yes... I should stop posting after midnight. Here, fully working, fully tested.

int i = oText1.Transparency;
while (i < 100) {
  i++;
  oText1.Transparency = i;
  Wait(1);
}

Title: Re: Various Objects Fading In the same room
Post by: luichy on Fri 28/11/2008 23:03:24
I tried it. But all of the objects fade in at the same time... How do I make them to fade one by one?
Title: Re: Various Objects Fading In the same room
Post by: on Fri 28/11/2008 23:10:31
How exactly do you want them to fade in/out? One after another is pretty simple- just repeat the "while loop code" for each one.

int i = 100;

while (i > 0) {
  i--;
  oText1.Transparency = i;
  Wait(1);
}

Wait(20);
i = 100;

while (i > 0) {
  i--;
  oText2.Transparency = i;
  Wait(1);
}

and so on.

If you want to fade in a different way, you may want to use timers, but for a simple sequence of fading objects, this example will work (I checked this time  ;) )
Title: Re: Various Objects Fading In the same room
Post by: luichy on Fri 28/11/2008 23:40:47
I think I have a basic problem here and is that all the objects are visible from the beggining.

I turned all the other objects visibility to false, then I could see the one first object I want to appear. But it fades in, then it flickers and fades in again.
Title: Re: Various Objects Fading In the same room
Post by: luichy on Fri 28/11/2008 23:50:12
GOT IT!!!

Just set the objects transparency at the room_Load function to 100.
Title: Re: Various Objects Fading In the same room
Post by: Trent R on Sat 29/11/2008 00:23:45
Ya, transparency and visibility are unrelated despite doing similar things.

~Trent
PS-For future reference, edit your post instead of double posting.
Title: Re: Various Objects Fading In the same room
Post by: luichy on Sat 29/11/2008 18:54:37
Thanks, I'll keep that in mind.