Still upon explosions

As far as I can see, I found, reading previous posts, that everybody needs some particle system that disappears after some update cycle, correct me if I'm wrong.



I thought it's possibile to add an something like that to various particle systems :



This causes :



Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
   at java.util.ArrayList.RangeCheck(Unknown Source)
   at java.util.ArrayList.get(Unknown Source)
   at com.jme.scene.Node.draw(Node.java:509)
   at com.jme.scene.Spatial.onDraw(Spatial.java:210)
   at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:1124)
   at it.phoenix.particle.ParticleManager.render(ParticleManager.java:156)


Can someone help ?

i would rather do that calculation on a controller added to the particle. then when you want to "kill" it, set the repeat type to RT_CLAMP and wait for the callback onDead from a particlecontrollerlistener and do removefromparent there…that way the particles won't disapear in mid air…

After all I think this is the best way :



package it.phoenix.scene;

import com.jme.scene.Node;
import com.jme.scene.SceneElement;
import com.jme.scene.Spatial;

public class TimedNode extends Node {

   private int times         = 1000;
   private int timesElapsed   = 0;
   
   public TimedNode (Spatial child, int times){
      this.attachChild(child);
      this.setTimes(times);
   }
   
   public void setTimes (int times){
      this.times = times;
   }
   
   public void update (){
      
   }
   
   public void updateGeometricState(float time, boolean initiator) {
      if (timesElapsed == times){
         this.removeFromParent();
         return;
      }
      timesElapsed++;
    }
}



So in you code you only need to do :


   scene.attachChild(new TimedNode (originalNode, timesToDisplay);



and call the updateGeometricState in the update cicle.

A little cleaner might be doing your logic in a ParticleInfluence.

would be rather painful to have to extend every object you wish to have a timed life. also, it would create an ugly object hierarchy i would never allow in my projects.

in your general time_any_node_and_removefromparent case you could do:



public class TimerController extends Controller {
   private float lifeTime = 0;
   private Spatial targetSpatial;

   public TimerController(Spatial targetSpatial, float lifeTime) {
      this.targetSpatial = targetSpatial;
      this.lifeTime = lifeTime;
   }

   public void update(float time) {
      lifeTime -= time;
      if (lifeTime < 0.0f) {
         targetSpatial.removeFromParent();
         targetSpatial.removeController(this);
      }
   }
}



and then just:


yourNode.addController(new TimerController(yourNode, 1.5f)); //die after 1.5 seconds



for any object who is a spatial...

What do I have to call in update cycle for the node ?

nothing…as long as it's attached to the scenegraph it's done automatically

Also - you are counting frames, not time, so it will be frame rate dependent.

Can i use that kind of logic, to use some explosion to vanish on demand AND be resuable in a pool ?

as i said in my first post. set the repeat type to RT_CLAMP and wait for the callback onDead from a particlecontrollerlistener. from there you can just send that particlesystem back into a pool