Game Development Community

Particles and Behaviors

by Anthony Rosenbaum · in Torque Game Builder · 04/10/2009 (12:19 pm) · 1 replies

Is there a way to set a particle effect as a default value for a behavior?

ie

%template.addBehaviorField( particleEffect, "The effect to use when popped", OBJECT, "", t2dParticleEffect);

The "" should allow you to set a default value, but it won't allow me to use a filename or referance to an executed effect

so in order to get particle working I create an fx on the classobject

function TheClass::onAddToScene(%this)
{


      %this.ParticleEffect = new t2dParticleEffect() 
      {
            scenegraph = $scenegraph; 
      };

     %this.ParticleEffect.loadEffect("~/data/particles/particles.eff");
}

then refernace it in the behavior like so

if (isObject(%this.Owner.particleEffect))
   {
      %explosion = %this.Owner.particleEffect.cloneWithBehaviors();
      %explosion.position = %position;
      %explosion.setEffectLifeMode("Kill", 1.0);
      %explosion.playEffect();
   }

This is haxsor and can't be right. Althought it works I keep getting this spam in the console


t2dSceneGraph::addToScene() - Object '1637' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1639' is already in a SceneGraph!.


Any thoughts?

#1
04/10/2009 (1:02 pm)
ANSWER:

Particle must be saved and named in the t2d scene (preferable off screen) to they can be referanced with the addBehaviorField()

The spammage was a result of calling cloneWithBehaviors(), in our case we were maknig many objects using that behavior so they were generating many fx so all I needed to do was simply clone() the particle FX