Flint Particle System Forum - Inverse Explosion Action Sun, 11 Dec 2011 01:02:58 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher Inverse Explosion Action http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1190#Comment_1190 http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1190#Comment_1190 Mon, 03 May 2010 19:12:23 +0100 seithein
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 http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1191#Comment_1191 Thu, 06 May 2010 01:00:24 +0100 seithein
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 http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1207#Comment_1207 Tue, 18 May 2010 08:06:31 +0100 Richard Inverse Explosion Action http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1256#Comment_1256 http://flintparticles.org/forum/comments.php?DiscussionID=351&Focus=1256#Comment_1256 Fri, 23 Jul 2010 12:32:50 +0100 figure8