Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthorWilliam
    • CommentTimeSep 6th 2011
     
    I want to use a bitmapdata photo as particles. At the beginning, it's scattered and can be any shape like linezone or pointzone,etc. And at the end the photo can be consisted of these moving particles. My codes like this:

    photo=new Bitmap();
    photo.bitmapData=new myPhoto();
    emitter=new Emitter2D();
    var particles:Array = Particle2DUtils.createRectangleParticlesFromBitmapData(photo.bitmapData,2,emitter.particleFactory,0,0);
    emitter.addExistingParticles(particles,true);
    renderer=new DisplayObjectRenderer();
    renderer.addEmitter(emitter);
    addChild(renderer);
    emitter.addInitializer(new Position(new LineZone(new Point(0,0),new Point(1003,0))));
    emitter.start();

    By use these codes I can't scatter the photo and change the shape at the beginning, it's a whole picture. Do anyone know how to make this effect?
    myPhoto is a png picture import in the .fla document
    • CommentAuthorRichard
    • CommentTimeSep 30th 2011 edited
     
    Flint doesn't contain an Action to tween the particle from a random position to its current position, so you'll need to create your own. Something like this should do it (this code is untested)

    package
    {
    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 org.flintparticles.twoD.zones.Zone2D;

    import flash.geom.Point;

    public class TweenToCurrentPosition extends ActionBase
    {
    private var startZone : Zone2D;

    public function TweenToCurrentPosition( startZone : Zone2D )
    {
    this.startZone = startZone;
    }

    override public function update( emitter : Emitter, particle : Particle, time : Number ) : void
    {
    var p : Particle2D = Particle2D( particle );
    if ( !p.dictionary[this] )
    {
    var start : Point = startZone.getLocation();
    p.dictionary[this] = { moveX:start.x - p.x, moveY:start.y - p.y, endX:p.x, endY:p.y };
    }
    var data : Object = p.dictionary[ this ];
    p.x = data.endX + data.moveX * p.energy;
    p.y = data.endY + data.moveY * p.energy;
    }
    }
    }


    With this code, you'll also need to add a Lifetime initializer (this is how long it takes for the particles to reach their destination) and an Age action.

    Richard