Flint Particle System Forum - Inverse Explosion Action 2011-12-11T00:54:48+00:00 http://flintparticles.org/forum/ Lussumo Vanilla & Feed Publisher Inverse Explosion Action http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1190#Comment_1190 2010-05-03T19:12:23+01:00 2010-05-03T19:12:48+01:00 seithein http://flintparticles.org/forum/account.php?u=362 Hi, First, thanks for sharing your awesome work. (And excuse my bad english) I wish to inverse explosion action. Get the particules back to there original position (after a mouse click for ...
First, thanks for sharing your awesome work. (And excuse my bad english)

I wish to inverse explosion action. Get the particules back to there original position (after a mouse click for exemple).
The pb is, the explosion is base on a Bitmap, so i don't use a Zone2D initialiser.
I can save particules positions at start and had a custom Action to get them back. but maybe there existing method that i didn't found.
If i inverse particules velocity i don't really know the best way to make them stop at original pos.
If i want to use TweenToZone, i don't have the starting Zone2D.
I tryed TweenToPosition but i don't think i can use it in this case.

All idea welcome,
thanks]]>
Inverse Explosion Action http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1191#Comment_1191 2010-05-06T01:00:24+01:00 2010-05-06T01:07:56+01:00 seithein http://flintparticles.org/forum/account.php?u=362 hello, I post a solution if anyone interested. I m pretty sure there a better way to do that, so all advices are welcome. (and again, thx for that great framework) Emitter2D Class : public ...
I post a solution if anyone interested. I m pretty sure there a better way to do that, so all advices are welcome.
(and again, thx for that great framework)

Emitter2D Class :

public class ImageExplode extends Emitter2D
{
//_______________________________________________________________________________O VAR

[Embed(source = "logo.png")]
public var Logo:Class;
private var _exploded:Boolean = false;

private var explosion:Explosion;
private var moveToOrigin:MoveToOrigin;


//_______________________________________________________________________________O CONSTRUCTOR
public function ImageExplode()
{
// - setup bitmapDataParticules
var logo:Bitmap = new Logo();
var particles:Array = Particle2DUtils.createRectangleParticlesFromBitmapData(logo.bitmapData, 10, particleFactory);
addExistingParticles( particles, false );

// - save origin pos in dictionary // should build a initialiser
var count:int = particles.length;
for (var i:int = 0; i < count; i++) {
particles[i].dictionary["xOrigin"] = particles[i].x;
particles[i].dictionary["yOrigin"] = particles[i].y;
}
// - activate Move
addAction(new Move());

}
public function explode(pStageX:Number,pStageY:Number ):void
{

if (!_exploded) {
// - remove Action
removeAction(moveToOrigin);
// - setup Explosion
explosion = new Explosion(0.5, pStageX, pStageY, 50 );
addAction(explosion);
_exploded = true;
}
else {
// - remove Action
removeAction(explosion);
// - go back to origin pos
moveToOrigin = new MoveToOrigin(this)
addAction (moveToOrigin);
_exploded = false;
}
}
}

Custom ActionBase class

public class MoveToOrigin extends ActionBase
{

public function MoveToOrigin(emitter:Emitter)
{
for (var i:int = 0; i < emitter.particles.length; i++) {
emitter.particles[i].velX *= -1;
emitter.particles[i].velY *= -1;
}

}

override public function update( emitter:Emitter, particle:Particle, time:Number ):void
{
var p:Particle2D = Particle2D( particle );
if (p.velX > 0) {
if (p.dictionary["xOrigin"] < p.x) {
initPart(p);
}
}
else {
if (p.dictionary["xOrigin"] > p.x) {
initPart(p);
}
}
}
private function initPart(particule:Particle2D):void {
particule.x = particule.dictionary["xOrigin"]; particule.velX = 0;
particule.y = particule.dictionary["yOrigin"]; particule.velY = 0;
}
}
]]>
Inverse Explosion Action http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1207#Comment_1207 2010-05-18T08:06:31+01:00 2011-12-11T00:54:48+00:00 Richard http://flintparticles.org/forum/account.php?u=1 Thank you for sharing this. Inverse Explosion Action http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1256#Comment_1256 2010-07-23T12:32:50+01:00 2011-12-11T00:54:48+00:00 figure8 http://flintparticles.org/forum/account.php?u=388 oh, this could help me out as well. i'll give it a try - thanks!