Game Development Community

How to delete particle effect?

by Denis Linardic · in Torque Game Builder · 10/15/2005 (12:43 pm) · 5 replies

This is probably a stupid question but I can't figure out so please help.

I create Particle effect.

//-----------------------------------------------------------------------------
// Create Player Smoke.
//-----------------------------------------------------------------------------
function attachSmoke(%mountObj, %mountPosition, %angle)
{
	// Create Player Thruster.
	%smoke = new fxParticleEffect2D() { scenegraph = spaceSceneGraph2D; };
	%smoke.loadEffect("~/client/effects/smoke.eff");
	%smoke.setLayer( %mountObj.getLayer()+1 );
	%smoke.mount( %mountObj, %mountPosition, 0, false );
	%smoke.setRotation( %angle );
	%smoke.playEffect();
}

This is in fxSceneObject2D::onCollision

If Hull integrity is lower than 20 then code attach Smoke particle to player.

// Decrease Player Shields.
  
 %srcObj.shields--;
   echo($player.shields);
   createExplosion( %srcObj );
   $playerHealth.setText("Shields: " SPC $player.shields);

      if ( %srcObj.shields > 20 )
        {
           echo("Hull integrity is greater then 20");
                  //attachSmoke.setEffectLifeMode( kill, 3 ); <---THIS IS WHAT BUGGING ME
         }
                         
    
   if ( %srcObj.shields < 20 )
          {
           //Hull integrity warning.
            $ScreenInfo.setText("W A R N I N G - Hull Integrity low!");
            attachSmoke( $player, "-0.12 -0.33", 0);
           // Schedule info removal.
            //schedule( 5000, 0, "EmptyInfo");
           }

Everything works fine until the point when player pickup Hull upgrade and then I have to remove all smoke particle effects.

The line thats bugging me is: //attachSmoke.setEffectLifeMode( kill, 3 );
I know that this doesn't work, so do you have any suggestion how could i kill that particle effect from here.

Thanks!

#1
10/15/2005 (1:11 pm)
By doing that, you're calling the attachsmoke function which will create a new particle effect and mount it on the player. When the kill limit is reached, that effect should die, but the original effect will still be playing.

You will either need a different function to destroy the smoke, or you need to add in some more options to your attachsmoke function that will allow you to get the ID of the smoke particle (if it exists) and then turn it off (if appropriate).
#2
10/15/2005 (1:22 pm)
Hmmm, maybe I could go with kill and then shedule attach particle if conditions are meet?

It's not realy a solution but I think it' could work...

ID solution is much cleaner i belive but I already doing that on few other places and sometimes I get weird slowdowns...It's probably my code but that's another story:)

Thanks!
#3
10/15/2005 (1:37 pm)
Ok I changed the code and now it look like this, it works for now but since I am not very good with T2D scripting I wonder if there could be problems with these.

//-----------------------------------------------------------------------------
// Create Player Smoke.
//-----------------------------------------------------------------------------
function attachSmoke(%mountObj, %mountPosition, %angle)
{
	// Create Player Thruster smoke.
	%smoke = new fxParticleEffect2D() { scenegraph = spaceSceneGraph2D; };
	%smoke.loadEffect("~/client/effects/smoke.eff");
	%smoke.setLayer( %mountObj.getLayer()+1 );
	%smoke.mount( %mountObj, %mountPosition, 0, false );
	%smoke.setRotation( %angle );
    %smoke.setEffectLifeMode( kill, 5 );
	%smoke.playEffect();
 schedule( 5000, 0, "playerHullStatus");
}

//-----------------------------------------------------------------------------
//Check Player Status
//-----------------------------------------------------------------------------
   function playerHullStatus()
   
if ( $player.shields < 20 )
   {
    //Hull integrity warning.
      $ScreenInfo.setText("W A R N I N G - Hull Integrity low!");
      attachSmoke( $player, "-0.12 -0.33", 0);
   }
#4
10/15/2005 (1:57 pm)
Something like this would probably be cleaner:

//-----------------------------------------------------------------------------
// Create Player Smoke.
//-----------------------------------------------------------------------------
function attachSmoke(%mountObj, %mountPosition, %angle)
{
   // Create Player Thruster.
   %smoke = new fxParticleEffect2D() { scenegraph = spaceSceneGraph2D; };
   %smoke.loadEffect("~/client/effects/smoke.eff");
   %smoke.setLayer( %mountObj.getLayer()+1 );
   %smoke.mount( %mountObj, %mountPosition, 0, false );
   %smoke.setRotation( %angle );
   %smoke.playEffect();
   %mountObj.smoke = %smoke;
}

// Decrease Player Shields.
  
 %srcObj.shields--;
   echo($player.shields);
   createExplosion( %srcObj );
   $playerHealth.setText("Shields: " SPC $player.shields);

      if ( %srcObj.shields > 20 )
        {
           echo("Hull integrity is greater then 20");
                  %srcObj.smoke.setEffectLifeMode( kill, 3 ); <---THIS IS WHAT BUGGING ME
         }
                         
    
   if ( %srcObj.shields < 20 )
          {
           //Hull integrity warning.
            $ScreenInfo.setText("W A R N I N G - Hull Integrity low!");
            attachSmoke( $player, "-0.12 -0.33", 0);
           // Schedule info removal.
            //schedule( 5000, 0, "EmptyInfo");
           }
#5
10/15/2005 (2:35 pm)
Ok now I am officialy a moron :) I work with %srcObj everywhere in collision event and still didn't realize!

Thanks Josh, it's much cleaner!!!