TGB/Behaviors/Blink Out

From TDN


Blink Out
Description:
This behavior will cause the object to exist for only a short period of time before blinking and then disappearing completely. This is good for pickups that go away if not picked up in time.


 Download:

Inline

Download the zip file and drag it onto the TGB window to add it to your project.



Back to Behavior Listing

//-----------------------------------------------------------------------------
// Blink Out Behavior
//-----------------------------------------------------------------------------

if ( !isObject( BlinkOutBehavior ) )
{
   %template = new BehaviorTemplate( BlinkOutBehavior );
   
   %template.friendlyName = "Blink Out";
   %template.behaviorType = "Effects";
   %template.description  = "Set a time to live before the object blinks out of existence.";
   
   %template.addBehaviorField( timeout, "Number of milliseconds before it begins to blink.", int, 3000 );
   %template.addBehaviorField( blinkTime, "Number of milliseconds to blink before delete.", int, 300 );
}

function BlinkOutBehavior::onAddToScene( %this, %scenegraph ) {
   %this.schedule( %this.timeout, "blink" );
}

function BlinkOutBehavior::blink( %this ) {
    if( %this.blinkTime > 0 ) {
        %this.owner.visible = !%this.owner.visible;
        %this.blinkTime--;
        
        %this.schedule( 2, "blink" );
    } else {
        %this.owner.safeDelete();
    }
}