Game Development Community

StartEffect / StopEffect

by Kevin James · in Torque Game Builder · 03/28/2005 (10:44 am) · 6 replies

I thought it would be cool to add a booster affect to the ship in the the Basic Tuturial:
%booster = new fxParticleEffect2D() { scenegraph = t2dSceneGraph; };
%booster.loadEffect("~/client/effects/magic_trail.eff");
%booster.mount( $player, "-0.12 -0.33", 0, false );
$player.booster=%booster;

when the user presses the 'x' key, the ship gets a boost of speed:
function boosterOn()
{
%x=$player.getLinearVelocityY();
if (%x!=0) $player.setLinearVelocityY(%x*3);

%x=$player.getLinearVelocityX();
if (%x!=0) $player.setLinearVelocityX(%x*3);

$player.booster.playeffect();
}

function boosterOff()
{
%x=$player.getLinearVelocityY();
if (%x!=0) $player.setLinearVelocityY(%x/3);

%x=$player.getLinearVelocityX();
if (%x!=0) $player.setLinearVelocityX(%x/3);

$player.booster.stopeffect();
}

It works the first time as expected. However, after that, the speed increases, but the booster effect does not play. This is the error:
T2D/client/client.cs (164): Unable to find object: '1238' attempting to call function 'playEffect'
T2D/client/client.cs (175): Unable to find object: '1238' attempting to call function 'stopEffect'

That tells me that the booster object gets killed by "StopEffect". I would not have expected that. Does the booster need to be re-created every time?

Thanks

About the author

Computer security, digital forensics, and platform jumper enthusiast. shells.myw3b.net/~syreal/


#1
03/28/2005 (10:59 am)
While the way I did it was indeed to create the effect whenever the player pulsed the thrusters (it just fit bette rin my game that way), I believe you can also re-use the existing effect. Instead of using stopEffect() try using setEffectLifeMode().
#2
03/28/2005 (11:08 am)
Thanks John. I tried setEffectLifeMode() and that works, but i want the affect to stop when 'x' is released, rather than based on timer. And yes, my approach works when the booster is created new in boosterOn():
function boosterOn()
{
%x=$player.getLinearVelocityY();
if (%x!=0) $player.setLinearVelocityY(%x*3);

%x=$player.getLinearVelocityX();
if (%x!=0) $player.setLinearVelocityX(%x*3);

%booster = new fxParticleEffect2D() { scenegraph = t2dSceneGraph; };
%booster.loadEffect("~/client/effects/magic_trail.eff");
%booster.mount( $player, "-0.12 -0.33", 0, false );
%booster.playeffect();
$player.booster=%booster;
}

That seems kinda wasteful. This is just a test, but what happens when I have 1,000 objects on the screen that need on/off/on effects?
#3
03/28/2005 (11:17 am)
Darren i'm still a noob with T2D myself so i'm learnign as I go :)
If you can wait a few minutes though I think I have an idea how this might work, I just need to code it out of my head and see if it works.
#4
03/28/2005 (11:19 am)
This works:
$player.booster.stopeffect(true,false);

apparently, "killeffect" is on by default.

Thanks
#5
03/28/2005 (11:19 am)
Lol

Thats exactly what I was goign to try but I wanted to test it first because the docs wording wasn't entirely clear.
#6
03/28/2005 (11:45 am)
Yeah, funny thing is that I read the docs before posting here in the forums and I totally misunderstood the part about "killeffect". Also, i tried this yesterday and it would work for the first 3-4 times before getting killed. Then today, it only worked once. Very weird.