Author | Message |
amilmand
Posts: 259
Location: --- Occupation: Age: V$: |
#136605 2018-02-02 21:19 |
You need to save the name of the particle you want to update this functionality is complex enough to warrant a separate class the most basic one can be this:
public class ParticleWrapper { Vector particleSystems = new Vector(); Vector particleNames = new Vector(); RenderRef particleRender = null; ParticleSystem particleRef = null; public void AddParticle(String name,ResourceRef map, int ParticleTypeID , Vector3 p, float rmin, float rmax, Vector3 vel, float vmin, float vmax, float freq, float globalFreq) { particleRender = new RenderRef(ParticleTypeID); particleRender.load(); particleRef = new ParticleSystem(map,particleRender,"scriptParticle"); particleRef.setSource(name, p, rmin, rmax, vel, vmin, vmax, freq, null); particleRef.setFreq(globalFreq); particleSystems.addElement(particleRef); particleNames.addElement(name); } public void UpdateParticle(String name, Vector3 p, float rmin, float rmax, Vector3 vel, float vmin, float vmax, float freq, float globalFreq) { for(int i = 0; i != particleNames.size(); i++) { if(particleNames.elementAt(i) == name) { particleSystems.elementAt(i).setSource(name, p, rmin, rmax, vel, vmin, vmax, freq, null); particleSystems.elementAt(i).setFreq(globalFreq); } } } public void CreateOrUpdateParticle(String name,ResourceRef map, int ParticleTypeID , Vector3 p, float rmin, float rmax, Vector3 vel, float vmin, float vmax, float freq, float globalFreq) { for(int i = 0; i != particleNames.size(); i++) { if(particleNames.elementAt(i) == name) { UpdateParticle(name, p, rmin, rmax, vel, vmin, vmax, freq, globalFreq); return; } } AddParticle(name,map, ParticleTypeID, p, rmin, rmax, vel, vmin, vmax, freq, globalFreq); } public void CleanParticles() { for(int i = 0; i != particleSystems.size();++i) { particleSystems.elementAt(i).destroy(); } particleSystems = new Vector(); particleNames = new Vector(); } } With this you can call the CreateOrUpdateParticle(..) function every time in the animate block and if you call it with a name already defined it wont create a new particle but instead move it but if the name does not belong to any particle yet it will create a new one. This post was edited by amilmand (2018-02-02 21:33, ago) |
|