Game Development Community

Another particleEffect question. Turning on and off?

by Jon Mitchell · in Torque Game Builder · 12/29/2006 (8:13 pm) · 4 replies

I am attempting to do something I though was fairly simple. When a key is pressed a sprite moves and a smoke trail comes out its end.

I had set up a function using a if else variable, the particle would start, but when the D key was let up the particle would continue, I added in an echo to test to see if the else section's condition was being reached, and it was. Every time I pressed D and let up the echo would respond to the console.

So after some searching I came up on two items that I tried to duplicate their methods, the first was in this forum trying to do the same thing I am trying to do, but this person was able to do it, but I am not quite sure exactly how:
http://www.garagegames.com/mg/forums/result.thread.php?qt=35664

I also looked into the asteroids source on TDN
http://tdn.garagegames.com/wiki/Torque_2D/GenreTutorials/AsteroidsPlayer

The asteroids one looked more like what I wanted to do, when I tried it, it failed with an error Unable to find object: '' attempting to call function 'playEffect'

Here are the different code variations I tried and failed on.

The first was just using a variable
function thruster)
{
	%thruster = new t2dParticleEffect() { scenegraph = SceneWindow2D.getScenegraph(); };
	%thruster.mount(pShip, "0 0", 0, false); // for specific/static un-reusable function
	%thruster.loadEffect("~/data/particles/jet.eff");
if ($playerThruster == True){
	%thruster.playEffect();
} else {
        %thruster.setEffectLifeMode( kill, 0.1 );  //Note I tried this with stopEffect(true, true) with no luck
                                                                       //Echoing would confirm the conditions are met though.
           }
}

The next was an attempt to clone the asteroids/smoke method which results in an error.

//movement section where thruster is called
function pShipRight()
{
   $pShip.moveRight = true;
   $pShip.updateMovement();
   $player.thruster.playEffect();
}


//function
function thruster() 
{
	%thruster = new t2dParticleEffect() { scenegraph = SceneWindow2D.getScenegraph(); };
	%thruster.mount(pShip, "0 0", 0, false); // for specific/static un-reusable function
	%thruster.loadEffect("~/data/particles/jet.eff");
         $player.thruster = %thruster;
}

I really would have liked to use the if/else method, is this not possible when dealing with a particle effect? If that is case where did I go wrong on my second try?
Thank you!

#1
12/29/2006 (8:48 pm)
I also wanted to ask about particles and linkpoints, they do not seem to get along from what I have read, is this true they you can not set a particle effect's location to be a link point?
#2
01/04/2007 (6:38 pm)
Just incase anyone comes around looking how to turn particle effects on and off for say turning a thruster on a jet on or off I did get it figured out and here are the code examples below that I added into the scroller example.

function pShipRight()
{
   $pShip.moveRight = true;
   $pShip.updateMovement();
   $pShip.newthruster = true;
   $pShip.updatenewthruster();
   $thruster.playEffect();
   
}



function pShipRightStop()
{
   $pShip.moveRight = false;
   $pShip.updateMovement();
   $pShip.newthruster = false;
   $pShip.updatenewthruster();
   $thruster.setEffectLifeMode( kill, 0.1 );
}



function playerShip::updatenewthruster(%this){
  if(%this.newthruster){
  %thruster = new t2dParticleEffect() { scenegraph = SceneWindow2D.getScenegraph(); };
	%thruster.loadEffect("~/data/particles/jet.eff");
	%thruster.setRotation(-90);
	%thruster.mount(pShip, "0, -1");
	$thruster = %thruster;
	}
}
#3
05/28/2007 (12:23 pm)
Thank you, this one might come in handy sometime... thx once again.
#4
06/25/2007 (9:41 am)
Quote:is this true they you can not set a particle effect's location to be a link point?

I don't know why that wouldn't work? I think that getLinkPoint() returns world coordinates so you'd have to use getLocalPoint() to get the object coordinates in order to mount it. However, I may be wrong and getLinkPoint() may return object coordinates. In that case you can just use that.