Better way maybe ?[solved]

Started by Candle, Sat 18/06/2005 06:03:34

Previous topic - Next topic

Candle

Have an object to fade out so doing it like this and it works for me but maybe a better way to do it ?
Code: ags

  // script for room: First time player enters screen

PlaySound(3); 
AnimateObject(0,0,0,1);
Wait(200);
SetObjectTransparency(0,40);
Wait(20);
SetObjectTransparency(0,60);
Wait(20);
SetObjectTransparency(0,80);
Wait(20);
SetObjectTransparency(0,100);
ObjectOff(0);

scotch

Code: ags

PlaySound(3); 
AnimateObject(0,0,0,1);
for(int i = 0; i<=100, i++) {
SetObjectTransparency(0,i);
Wait(1);
}
ObjectOff(0);


This what you want?

strazer

There are no for-loops in AGS:

Code: ags

  PlaySound(3);
  AnimateObject(0, 0, 0, 1);
  int i = 0;
  while(i <= 100) {
    SetObjectTransparency(0, i);
    Wait(1);
    i++;
  }
  ObjectOff(0);

scotch

Hmm, could have sworn there were.  Been working on some game in C++ for the past few days, my mind is stuck in that mode.

DoorKnobHandle

#4
You can always write a function to fade out an object (especially useful when you want to fade out more than one object in your game)...

Code: ags

function ObjectFadeOut ( int ObjectID, int Speed, int SoundID )
{ 
   if ( SoundID > -1 )
      PlaySound ( SoundID );

   AnimateObject ( ObjectID, 0, 0, 1 );

   if ( Speed < 1 )
      Speed = 1;
   
   if ( Speed > 10 )
      Speed = 10;

   int i = 0;
   while ( i <= 100 )
   {
      SetObjectTransparency ( ObjectID, i );
      Wait ( Speed );
      i++;
   }

   ObjectOff ( ObjectID );
}


Now you can call the function whenever you want to fade out an object like this:

Code: ags

ObjectFadeOut ( 3, 1, 2 );


That would fade out the object 3 with a speed of 1 and play the sound 2.

So the first parameter is the object number, the second is the speed ( from 1 to 10 where 1 is the fastest and10 the slowest ) and the sound number that you want to play with the fade out animation ( use -1 for no sound )!

Also note that the function is blocking...


Candle

Thank you guys . I like the last one but the sound will change as it is a voice talking so would change to what ever the need would be at that time . So will use that and just not add the voice to the script .
Thanks again .

Candle

#6
Just one question here .
I have this but it runs the object two times then fades out the object .
I like it to run the one time then fade the object out .
Code: ags

// script for room: First time player enters screen
  
SetObjectView(0,9);
AnimateObject(0,0,0,0);
Wait(120);
ObjectFadeOut ( 0, 1,0);

I got it ..
Code: ags

function ObjectFadeOut ( int ObjectID, int Speed )
{ 
if ( Speed < 1 )
      Speed = 1;
   
   if ( Speed > 10 )
      Speed = 10;

   int i = 0;
   while ( i <= 100 )
   {
   
 
      SetObjectTransparency ( ObjectID, i );
      Wait ( Speed );
      i++;
   }

   ObjectOff ( ObjectID );
}

Now it does just what I want .

SMF spam blocked by CleanTalk