Fade in object (loop not working) (SOLVED)

Started by , Mon 08/01/2007 22:36:39

Previous topic - Next topic

goldenTouch

Hi,

I have a small problem. I have looked at other posts for a very long time, but I can't find an explanation to this.

I have two methods that are called from my module's repeatedly_execute_always function.
At the moment the function calls one of the functions, and I change which one programmatically.
In other words, the execute_always thing does not have any real content, and can not be causing the problem. It just sets the default values which are object.Transparency = 0 or 100.

The CreditFadeOut function works perfectly.
The CreditFadeIn function seems to be caught in a loop.

Here's the code:

Code: ags
//-------------------------------------------------------------------
// Function CreditFadeOut
//
// This method will fade out the credits.
//-------------------------------------------------------------------
function CreditFadeOut() {
  
  // As long as the object's transparancy value is less than 100
  // continue to fade out.
  if (object[0].Transparency < 100) {
		
    object[0].Transparency = object[0].Transparency + 1;
		
  } else { // Stop when it reaches 100.
		
    fs = fsWaiting; // this sets fs to 2 - has no meaning yet.
		
  } // end if
			
} // end function



//-------------------------------------------------------------------
// Function CreditFadeIn
//
// This method will fade in the credits.
//-------------------------------------------------------------------
function CreditFadeIn() {
  
  // As long as the object's transparancy value is less than 100
  // continue to fade out.
  if (object[0].Transparency > 0) {
		
    object[0].Transparency -= 1;
    cBenjamin.SayBackground(String.Format("Transparency: %d", object[0].Transparency));
  } else { // Stop when it reaches 0.
		
    fs = fsWaiting; // this sets fs to 2 - has no meaning yet.
		
  } // end if
			
} // end function


As you can see I put in a Speech in the background to see what the value of the Transparency is. It stays at 100. So it does get called, the line is executed, but the value for that object's transparency does not change.

Why is that?

strazer

The .Transparency property doesn't actually have a full 101 levels, the value is being rounded internally, so increasing/decreasing it by a mere 1 level won't always cause it to change.

See also this thread.

The workaround is using a variable, so instead of

Code: ags

  if (object[0].Transparency > 0) {
    object[0].Transparency -= 1;
  }


do this:

Code: ags

  int myTransparency = object[0].Transparency;

  //...

  if (myTransparency > 0) {
    object[0].Transparency = myTransparency;
    myTransparency -= 1;
  }

goldenTouch

Thank you for your help.
That solved the problem.


SMF spam blocked by CleanTalk