Stop a loop at runtime using a3dparticle?

Software: Away3D 4.x

Kevin, Newbie
Posted: 12 June 2013 08:15 PM   Total Posts: 3

Hello,

I’ve run into an issue that I simply can not seem to find an answer for, and I was hoping that somebody here would be able to give me a hand. I’ll attach my code as well, to make it easier to understand.

I am using Away3D 4.0 Gold.

If you imagine an arrow on fire is shooting towards a player, you want the smoke to follow the arrow on loop until it hits the target. Once it hits the target, you want the loop to stop, but for the smoke that has already been placed onscreen to continue the colortransform.

So, my question is this:

Is it possible to change particle.loop = true, to particle.loop = false on a ParticlesContainer? Or is there some other way of doing this?

In the below example, a frost circle will be made. The theory is it should spin twice, and then stop spinning as loop is changed to false.

package spells
{
 import a3dparticle
.animators.actions.acceleration.AccelerateGlobal;
 
import a3dparticle.animators.actions.color.ChangeColorByLifeGlobal;
 
import a3dparticle.animators.actions.position.OffsetPositionLocal;
 
import a3dparticle.animators.actions.rotation.BillboardGlobal;
 
import a3dparticle.animators.actions.velocity.VelocityLocal;
 
import a3dparticle.generater.MutiWeightGenerater;
 
import a3dparticle.generater.SingleGenerater;
 
import a3dparticle.particle.ParticleColorMaterial;
 
import a3dparticle.particle.ParticleParam;
 
import a3dparticle.particle.ParticleSample;
 
import a3dparticle.ParticlesContainer;
 
import particleEditor.effect.param.vars.RandomGlobeVarEditor
 import away3d
.containers.ObjectContainer3D;
 
import away3d.primitives.*;
 
import flash.geom.ColorTransform;
 
import flash.geom.Vector3D;
 
import flash.utils.setTimeout;
 
 
/**
  * ...
  * @author liaocheng
  */
 
public class FrostCircle extends ObjectContainer3D 
 {
  
  
private var particle:ParticlesContainer;
  
  private var 
sample1:ParticleSample;
  
  public function 
FrostCircle():void 
  {
   
//step 1:we create a sample
   
var material:ParticleColorMaterial = new ParticleColorMaterial();
   var 
plane:SphereGeometry = new SphereGeometry(3055);
   
sample1 = new ParticleSample(plane.subGeometries[0]material);
   
   
//step 2:we create a generater which will group the samples.
   
var generater:SingleGenerater = new SingleGenerater(sample1200);
   
   
//step 3: we create a container and set some attributes.
   
particle = new ParticlesContainer();
   
particle.loop true;
   
particle.hasDuringTime true;
   
   
//step 4:we add some actions to the container.
   
var action1:VelocityLocal = new VelocityLocal();
   
particle.addAction(action1);
   
   var 
action2:OffsetPositionLocal = new OffsetPositionLocal();
   
particle.addAction(action2);
   
   var 
action3:ChangeColorByLifeGlobal = new ChangeColorByLifeGlobal(new ColorTransform(0.85110.750000), new ColorTransform(0.20.80.800000) );
   
particle.addAction(action3);
   
   var 
action4:AccelerateGlobal = new AccelerateGlobal(new Vector3D(-5205));
   
particle.addAction(action4);
   
   
//step 5:we set the param function whose return value will be used for actions
   
particle.initParticleFun initParticleParam;
   
   
//finally,we generate the particles,and start
   
particle.generate(generater);
   
particle.start();
   
   
addChild(particle);

   
setTimeout(function():void { particle.loop false }6500);
   
   
setTimeout(function():void { removeChild(particle); }10400);
  
}
  
  
private function initParticleParam(param:ParticleParam):void
  {
   
var wrkincrease:Number 4.7;
   
   
param.startTime Math.random();
   
param.duringTime wrkincrease param.startTime;
   var 
degree:Number Math.random() * 360;
   var 
cos:Number Math.cos(degree);
   var 
sin:Number Math.sin(degree);
   var 
r:Number 700;
   var 
r2:Number Math.random() * 10;
   var 
degree1:Number param.startTime Math.PI * (wrkincrease 2);
   var 
degree2:Number Math.PI *80180 Math.random() * Math.PI5180;

   
param["VelocityLocal"= new Vector3D(20 Math.random() * 40Math.random()*520 Math.random() * 40);
   
param["OffsetPositionLocal"= new Vector3D(Math.sin(degree1) * Math.cos(degree2), 0Math.cos(degree1) * Math.cos(degree2));
  
}
  
 }
 
   

Kevin, Newbie
Posted: 13 June 2013 02:09 PM   Total Posts: 3   [ # 1 ]

In-case somebody needs this for the future - It does not seem possible to do the above.

The only way I found it possible was to create a manual loop, which runs through the original particles and clones them. When you call stop, the current stage of the loop continues until it has finished (all alpha gone), and then removes the children from the stage.

It’s slightly more resource intensive, but I could not find any other way of achieving this.

package spells
{
 import a3dparticle
.animators.actions.acceleration.AccelerateGlobal;
 
import a3dparticle.animators.actions.color.ChangeColorByLifeGlobal;
 
import a3dparticle.animators.actions.position.OffsetPositionLocal;
 
import a3dparticle.animators.actions.rotation.BillboardGlobal;
 
import a3dparticle.animators.actions.velocity.VelocityLocal;
 
import a3dparticle.generater.MutiWeightGenerater;
 
import a3dparticle.generater.SingleGenerater;
 
import a3dparticle.particle.ParticleColorMaterial;
 
import a3dparticle.particle.ParticleParam;
 
import a3dparticle.particle.ParticleSample;
 
import a3dparticle.ParticlesContainer;
 
import away3d.core.base.Object3D;
 
import flash.display.BlendMode;
 
import particleEditor.effect.param.vars.RandomGlobeVarEditor
 import away3d
.containers.ObjectContainer3D;
 
import away3d.primitives.*;
 
import flash.geom.ColorTransform;
 
import flash.geom.Vector3D;
 
import flash.utils.setTimeout;
 
import flash.utils.setInterval;
 
import flash.utils.clearInterval;
 
 
/**
  * ...
  * @author KM
  */
 
public class Frost extends ObjectContainer3D 
 {
  
  
private var particle :ParticlesContainer;
  
  private var 
sample  :ParticleSample;
  
  private var 
_array  :Vector.<ParticlesContainer> = new Vector.<ParticlesContainer>();
  private var 
_interval :uint;
  private var 
_i   :int 0;
  
  private var 
_duplicationTime :Number 1000;
  private var 
_removeCount  :int 3;
  
  public function 
Frost():void 
  {
   
var material:ParticleColorMaterial = new ParticleColorMaterial();
   
material.blendMode BlendMode.ADD;
   var 
plane:SphereGeometry = new SphereGeometry(3055);
   
sample = new ParticleSample(plane.subGeometries[0]material);
   
   var 
generater:SingleGenerater = new SingleGenerater(sample50);
   
   
particle = new ParticlesContainer();
   
particle.hasDuringTime true;
   
   var 
action1:VelocityLocal = new VelocityLocal();
   
particle.addAction(action1);
   
   var 
action3:ChangeColorByLifeGlobal = new ChangeColorByLifeGlobal(new ColorTransform(00010000), new ColorTransform(0.20.80.800000) );
   
particle.addAction(action3);
   
   var 
action4:AccelerateGlobal = new AccelerateGlobal(new Vector3D(-100105));
   
particle.addAction(action4);
   
   
particle.initParticleFun initParticleParam;
   
   
particle.generate(generater);
   
particle.start();
   
   
addChild(particle);
   
   
// USED TO LOOP WHERE CANCELLING IS POSSIBLE
   
_interval setInterval(beginDuplication_duplicationTime);
   
setTimeout(cancelDuplication6000);
  
}
  
  
private function beginDuplication():void {   
   
var wrkparticle:ParticlesContainer particle.clone() as ParticlesContainer;
   
_array[_i] wrkparticle;
   
   
addChild(_array[_i]);
   
   if (
_i _removeCount{
    removeChild
(_array[_i _removeCount 1]);
    if (
this.contains(particle)) {
     removeChild
(particle);
    
}
   }
   
   _i
++;
  
}
  
  
private function cancelDuplication():void {
   trace
("Cancelled");
   
clearInterval(_interval);
   
   
setTimeout(removeFromStage_duplicationTime _removeCount);
   
   function 
removeFromStage():void {
    
for (var i:int _i _removeCount 1_ii++) {
     removeChild
(_array[i]);
    
}
    
    _i 
0;
   
}
  }
  
  
private function initParticleParam(param:ParticleParam):void
  {
   
var wrkincrease:Number 1;
   
   
param.startTime Math.random();
   
param.duringTime wrkincrease param.startTime;

   
param["VelocityLocal"= new Vector3D(-(Math.random() * 20), Math.random(), -(Math.random() * 20));
  
}
  
 }
 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X