Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
How do I?: How to change position of particle after emitter is already made?
Bottom of Page1 to 3 of 3
-
- CommentAuthorxraven13
- CommentTimeJan 22nd 2010 edited
I made a class DotEmitter that extends Emitter2D and all its working fine when i make a instance, particle appears on the screen..
Now i am wondering how to move position of that particle around so that it follows for example some position or actually and place on screen i want...
I would like to set x and y of that particle so that he appears there...
In DotEmitter class i have this variable :public var point:PointZone = new PointZone(new Point(335,100));
And i initilize it like this :addInitializer( new Position(point));
So when i make instance i tried changing position of particle like this :emitter.point.point.x = 500;
But particle didn't move at that position!!!
When i trace emitter.point.point.x i got 500!!! So particle is at that position but it seems he didn't update??
So i tried using emitter.update etc but nothing happened..
What i am doing wrong?
Thx in advance for help! -
- CommentAuthorRichard
- CommentTimeJan 25th 2010
Hi
The position initializer sets the position of new particles, it doesn't change the position of existing particles. Initializers set the propertioes of new particles when they are created, while Actions alter properties of existing particles. There isn't an action to manually set the position of existing particles, but you may be able to get what you need using a TweenToZone action with your PointZone and adjusting the time in the TweenToZone to get it there quickly.
Richard -
- CommentAuthorxraven13
- CommentTimeJan 25th 2010
Ok. I made my own custom action that moves particle to some position. Just change point.x and point.y after emitter is made to move position of their particles :)
BTW i am adding width and height to make that particle is at same place where my sprite is .. So if you don't want something like that just remove width and height..
package org.flintparticles.twoD.actions
{
import org.flintparticles.common.actions.Action;
import org.flintparticles.common.actions.ActionBase;
import org.flintparticles.common.emitters.Emitter;
import org.flintparticles.common.particles.Particle;
import org.flintparticles.twoD.particles.Particle2D;
import flash.geom.Point;
public class MoveTo extends ActionBase
{
public var x:Number;
public var y:Number;
public var width:Number;
public var height:Number;
public function MoveTo(_x:Number=0,_y:Number=0,_width:Number=0,_height:Number=0)
{
this.x = _x;
this.y = _y;
this.width = _width/2;
this.height = _height/2;
}
override public function update( emitter:Emitter, particle:Particle, time:Number ):void
{
var p:Particle2D = Particle2D( particle );
p.x = x + width;
p.y = y + height;
}
}
}
1 to 3 of 3
