Flint Particle System Forum - Change Initializer after Particles are generated Thu, 23 Jun 2011 16:31:20 +0100 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher Change Initializer after Particles are generated http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=825#Comment_825 http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=825#Comment_825 Tue, 23 Jun 2009 05:51:58 +0100 kranke
I need to know if I can modify the initializers after the emitter is generated. For example I need a bunch of floating particles to come together to form a line of text (in shape), then fade the matching bitmap text right on top. Next to expand again and back to another line of text and so forth.

So I have something like this
public function CloudEmitter(stage:DisplayObject)
{
motaLogo = Bitmap(new Mota()).bitmapData;
counter = new Blast(300);
motaParticles = new InitializerGroup();
motaParticles.addInitializer(new PV3DObjectClass(Particle, null, 4));
motaParticles.addInitializer(new MassInit(1));
motaParticles.addInitializer(new CollisionRadiusInit(2));
motaParticles.addInitializer(new ApplyMaterial(ParticleMaterial, 0xFFFFFFFF, 0, ParticleMaterial.SHAPE_CIRCLE));
motaParticles.addInitializer(new ColorInit(0xFF6600FF, 0xff4455FF));

motaParticles.addInitializer(new Position(new BoxZone(280, 280, 280, new Vector3D(0, 0, 0), new Vector3D(1, 1,1), new Vector3D(2, 2, 1))));
motaParticles.addInitializer(new Velocity(new SphereZone(new Vector3D(0, 0, 0), 10, 10)));

addInitializer(new ChooseInitializer([motaParticles], [19]));
addAction(new Move());
addAction(new BoundingBox(-150, 150, -150, 150, -150, 150, 1));
}

private function setToHeadline1():void
{
motaParticles.addInitializer(new Position(new BitmapDataZone(motaLogo,new Vector3D(0, 0, 0), new Vector3D(180, 0, 0),new Vector3D(0, 90, 0))));
}

Where function setToHeadline is my text line, see I can actually have either or. I really need to be able to animate from one to another.


Please help. ]]>
Change Initializer after Particles are generated http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=826#Comment_826 http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=826#Comment_826 Tue, 23 Jun 2009 12:19:39 +0100 SanMajo
public function CloudEmitter(stage:DisplayObject)
{
private var motaPosition:Position = new Position(new BoxZone(280, 280, 280, new Vector3D(0, 0, 0), new Vector3D(1, 1,1), new Vector3D(2, 2, 1)));

...

// and later:
private function setToHeadline1():void
{
motaPosition.zone = new BitmapDataZone(motaLogo,new Vector3D(0, 0, 0), new Vector3D(180, 0, 0),new Vector3D(0, 90, 0));
}


This will not solve your problem with tweening particles from one position to another but this is a better way to change initializers after the emitter started.

I dont know if there is an easier solution for your problem but you could look at:
org.flintparticles.threeD.actions.TweenPosition - With that you could tween (move) the particles between two Vectors (but you would have to set it for every particle)
org.flintparticles.threeD.actions.ZonedAction - With this you could add friction to the particles only if they are within the specified zone (for example your bmp text)
this could create an effect of particles swirling around your text and stick on it if they hover above it.

there are many solutions to your problem, but you have to try some to choose which looks best.

kind regards ]]>
Change Initializer after Particles are generated http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=829#Comment_829 http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=829#Comment_829 Tue, 23 Jun 2009 18:36:45 +0100 kranke
Thank you much for your prompt response, it seems that the answer still eludes me. I tried the changes you suggested to not avail. Try hitting shift key and nothing man... Note that I am instantiating this as an emitter in my main class.

Here is the new code

private var motaPosition:Position;

public function CloudEmitter(stage:DisplayObject)
{

counter = new Blast(300);

motaLogo = Bitmap(new Mota()).bitmapData;
motaPosition = new Position(new BoxZone(280, 280, 280, new Point3D(0, 0, 0), new Vector3D(1, 1, 1), new Vector3D(2, 2, 1)));

motaParticles = new InitializerGroup();
motaParticles.addInitializer(new PV3DObjectClass(Particle, null, 4));
motaParticles.addInitializer(new MassInit(1));
motaParticles.addInitializer(new CollisionRadiusInit(2));
motaParticles.addInitializer(new ApplyMaterial(ParticleMaterial, 0xFFFFFFFF, 0, ParticleMaterial.SHAPE_CIRCLE));
motaParticles.addInitializer(new ColorInit(0xFF6600FF, 0xff4455FF));

// Modified line
motaParticles.addInitializer(motaPosition);

motaParticles.addInitializer(new Velocity(new SphereZone(new Point3D(0, 0, 0), 10, 10)));
addInitializer(new ChooseInitializer([motaParticles], [19]));
addAction(new Move());
addAction(new BoundingBox(-150, 150, -150, 150, -150, 150, 1));

// Click shift to change position initializer
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true);
}

private function keyDownListener(ev:KeyboardEvent):void
{
if (motaParticles && ev.keyCode == Keyboard.SHIFT)
{
setToHeadline1();
}
}

public function setToHeadline1():void
{
motaPosition.zone = new BitmapDataZone(motaLogo, new Point3D(0, 0, 0), new Vector3D(180, 0, 0), new Vector3D(0, 90, 0));
trace("Not working still?")
} ]]>
Change Initializer after Particles are generated http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=836#Comment_836 http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=836#Comment_836 Wed, 24 Jun 2009 21:33:35 +0100 SanMajo
im sorry if i confused you with my answer ;-)
The above code cannot work like you expect because initializers only influence particles that are created after they were set!
you are creating particles with a blast counter -> so you cant influence them afterward! thats only possible with actions

i only wanted to show you how you could in general change initializers after an emitter has started.

My real answer to your problem were the second thoughts:

org.flintparticles.threeD.actions.TweenPosition - With that you could tween (move) the particles between two Vectors (but you would have to set it for every particle)
org.flintparticles.threeD.actions.ZonedAction - With this you could add friction to the particles only if they are within the specified zone (for example your bmp text)
this could create an effect of particles swirling around your text and stick on it if they hover above it.


kind regards ]]>
Change Initializer after Particles are generated http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=837#Comment_837 http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=837#Comment_837 Thu, 25 Jun 2009 02:46:34 +0100 kranke
Ok, I think TweenPosition will work great, when you say set it for every particle I should do a for each loop right?

Question: could I add an explosion to my Emmiter then use removeAction to put it back the way it was?

I tried putting the action as such and nothing

emitter.start();

explode = new Explosion(500, new Point3D(0, 0, 0), 500, 20);

addEventListener(Event.ENTER_FRAME, render);
// Click shift to change position initializer
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpListener, false, 0, true);
}

private function keyDownListener(ev:KeyboardEvent):void
{
trace("down");
emitter.addAction(new Move());
emitter.addAction(explode);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownListener, false);
}

private function keyUpListener(ev:KeyboardEvent):void
{
trace("up");

emitter.removeAction(explode);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true);
}

So removing the action is not working as intended?

Sorry for many questions, I hope there is an answer... ]]>
Change Initializer after Particles are generated http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=838#Comment_838 http://flintparticles.org/forum/comments.php?DiscussionID=226&Focus=838#Comment_838 Thu, 25 Jun 2009 08:09:35 +0100 Richard
To be clear, as SanMajo said, Initializers only affect particles when they are created. Once a particle has been created, no ampount of tinkering with initializers will affect it.

Actions affect particles every frame. However, the effect that actions have had on the particles cannot be undone by removing the action. Removing the action simply prevents it affecting the particles in the future.

You have two options.

1. Use one or more actions to pull the particles towards the text, then stop them when they reach the text. To pull the particles towards the text you might try GravityWell. To stop them when they reach the text (use contains() on a BitmapDataZone to find if they're inside the bitmap), you could set their velocity to zero and add a very high friction, or something like that.

2. I think a better option, but perhaps not so easy, is to write a custom action. Look in the TweenPosition action and try altering it to your needs. The target of the tween (endX, endY) should be a custom value for each particle (store the target values inside each particle's dictionary), and use getLocation() on a BitmapDataZone to get this target. You'll also want to manage the duration of the tween independently - the current tween bases it's duration on the lifetime of the particle, which means it that the particle will die when the tween completes, and you don't want that to happen. If you get the action right, adding it to the emitter will cause all your particles to move to points within the bitmap. ]]>