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(30, 5, 5);
sample1 = new ParticleSample(plane.subGeometries[0], material);
//step 2:we create a generater which will group the samples.
var generater:SingleGenerater = new SingleGenerater(sample1, 200);
//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.85, 1, 1, 0.75, 0, 0, 0, 0), new ColorTransform(0.2, 0.8, 0.8, 0, 0, 0, 0, 0) );
particle.addAction(action3);
var action4:AccelerateGlobal = new AccelerateGlobal(new Vector3D(-5, 20, 5));
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 *80/ 180 + Math.random() * Math.PI* 5/ 180;
param["VelocityLocal"] = new Vector3D(20 - Math.random() * 40, Math.random()*5, 20 - Math.random() * 40);
param["OffsetPositionLocal"] = new Vector3D(r * Math.sin(degree1) * Math.cos(degree2), 0, r * Math.cos(degree1) * Math.cos(degree2));
}
}
}