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
%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/
#2
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?
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
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.
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
$player.booster.stopeffect(true,false);
apparently, "killeffect" is on by default.
Thanks
03/28/2005 (11:19 am)
This works:$player.booster.stopeffect(true,false);
apparently, "killeffect" is on by default.
Thanks
#5
Thats exactly what I was goign to try but I wanted to test it first because the docs wording wasn't entirely clear.
03/28/2005 (11:19 am)
LolThats 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.
Torque Owner John Vanderbeck
VanderGames