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

  1.  
    Apologies for not trawling the forum for answers, I thought this would be an easy one for people familiar with Flint to answer. I would really like to use Flint for an animation that I need to create, just need to know if I can do the following, just yes or no will do, I will learn how to do it if its possible.

    1. Can I create particles from any display object I create, eg. some bubbles that open up with text in when I click them?
    2. Is it possible to make certain particles get attracted to one I click on?
    3. Can you change the movement behaviour at runtime?

    Many thanks,

    Neil
  2.  
    Ok, so I had some time today and I went through the forum posts and I have answers to my first two questions, i'll get to number 3 when I get the chance. I seem to be getting two click events dispatched when I click on a particle. MyParticle is just a class which extends Sprite, with a circle drawn in the graphics property.

    Any ideas?


    package
    {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.Point;

    import org.flintparticles.common.counters.Blast;
    import org.flintparticles.common.displayObjects.Star;
    import org.flintparticles.common.initializers.CollisionRadiusInit;
    import org.flintparticles.common.initializers.ImageClass;
    import org.flintparticles.common.initializers.MassInit;
    import org.flintparticles.twoD.actions.BoundingBox;
    import org.flintparticles.twoD.actions.Collide;
    import org.flintparticles.twoD.actions.Move;
    import org.flintparticles.twoD.actions.Rotate;
    import org.flintparticles.twoD.emitters.Emitter2D;
    import org.flintparticles.twoD.initializers.Position;
    import org.flintparticles.twoD.initializers.RotateVelocity;
    import org.flintparticles.twoD.initializers.Velocity;
    import org.flintparticles.twoD.renderers.DisplayObjectRenderer;
    import org.flintparticles.twoD.zones.DiscZone;
    import org.flintparticles.twoD.zones.RectangleZone;

    [SWF (backgroundColor="#000000")]
    public class FlintTest extends Sprite
    {
    protected static const PARTICLE_COUNT:int = 25;
    protected var emitter:Emitter2D;

    public function FlintTest()
    {
    emitter = new Emitter2D();
    var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
    renderer.mouseChildren = true;
    renderer.mouseEnabled = true;
    renderer.addEventListener(MouseEvent.CLICK, clickHandler);
    renderer.addEmitter(emitter);
    addChild(renderer);

    emitter.counter = new Blast(PARTICLE_COUNT);
    emitter.addInitializer(new Position(new RectangleZone(0,0,stage.stageWidth, stage.stageHeight)));
    emitter.addInitializer(new ImageClass(MyParticle));

    var zone:DiscZone = new DiscZone(new Point(0, -50), 100, 10);
    emitter.addInitializer(new Velocity(zone));
    emitter.addInitializer(new CollisionRadiusInit(20));
    emitter.addInitializer(new MassInit(Math.random()*0.1));
    emitter.addInitializer( new RotateVelocity(-Math.PI / 2, Math.PI / 2));

    emitter.addAction(new Move());
    emitter.addAction(new BoundingBox(0,0,stage.stageWidth, stage.stageHeight));
    emitter.addAction(new Collide());
    emitter.addAction(new Rotate());
    emitter.start();

    for(var i:int = 0; i < renderer.numChildren; i++)
    {
    var particle:Sprite = Sprite(renderer.getChildAt(i));
    particle.useHandCursor = true;
    particle.buttonMode = true;
    particle.addEventListener(MouseEvent.CLICK, clickHandler);
    }
    }

    protected function clickHandler(event:MouseEvent):void
    {
    trace("clicked: " + event.target.name)
    }
    }
    }
    • CommentAuthorRichard
    • CommentTimeJan 18th 2011
     
    Your listening for clicks on both the particles and the renderer. That's why you receive two click events. You need only listen on one of these.

    You can modify behaviour at runtime by either

    1. adding and removing actions from/to the emitter to change the behaviour.
    2. using an action that alters its behaviour dynamically (writing your own actions is not hard - look in the source code of a few of the included actions for clues).

    Richard
  3.  
    Thanks for the reply Richard, I created a custom action to check if there is a listener attached or not, and adds one if needed. The current example I'm working on now uses a SineCounter so I would ideally like to remove the listeners when the particles die, where would be the best place to do that?

    Neil
  4.  
    Apologies for not reading the docs more thoroughly, I found ParticleEvent.PARTICLE_DEAD.

    Cheers