Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthorseithein
- CommentTimeMay 3rd 2010 edited
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 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 -
- CommentAuthorseithein
- CommentTimeMay 6th 2010 edited
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 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;
}
} -
- CommentAuthorRichard
- CommentTimeMay 18th 2010
Thank you for sharing this. -
- CommentAuthorfigure8
- CommentTimeJul 23rd 2010
oh, this could help me out as well. i'll give it a try - thanks!
1 to 4 of 4
