Various Objects Fading In the same room [SOLVED]

Started by luichy, Fri 28/11/2008 00:22:15

Previous topic - Next topic

luichy

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.

Ghost

#1
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

Code: ags

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.

Trent R

#2
I'll also add that if you want it to fade faster, increase the value of i more
Code: ags
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.
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Dualnames

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);
}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ghost

#4
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.

Trent R

Ghost, shouldn't yours be <100? You have >0 along with ++ which should loop even when it's fully invisible...

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Ghost

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);
}


luichy

I tried it. But all of the objects fade in at the same time... How do I make them to fade one by one?

Ghost

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  ;) )

luichy

#9
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.

luichy

GOT IT!!!

Just set the objects transparency at the room_Load function to 100.

Trent R

Ya, transparency and visibility are unrelated despite doing similar things.

~Trent
PS-For future reference, edit your post instead of double posting.
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

luichy


SMF spam blocked by CleanTalk