Fork me on GitHub
Not signed in (Sign In)
    • CommentAuthorromu
    • CommentTimeSep 1st 2011
    First time for me with Flint.

    I hoped to find a bit of help in what I want to do here.

    The idea is simple, every time the user use the keyboard (on a keydown event then), I'll show the letter he typed with a big scale, scaling down to a point I'll dynamically change.

    So here is what I've done so far.

    addInitializer( new SharedImage( new DummyLetterForTest() ) );
    addInitializer(new Lifetime(0.7, 0.7));
    addInitializer(new Position(new RectangleZone(0, 0, ContentArea.WIDTH, ContentArea.HEIGHT)));

    addAction(new Age(Exponential.easeOut))
    addAction(new TweenToZone(new PointZone(new Point(ContentArea.WIDTH >> 1, ContentArea.HEIGHT >> 1))))
    addAction(new ScaleImage(3, 0.5));
    addAction(new Fade(1, 0.3))

    This animation looks good for now.

    Now my problem is to trigger the emitter on a key down event.

    I tried different approach:

    1. counter

    I've created a KeyDownCounterTrigger that works as the shipped KeyDownCounter beside that it doesn't take any special key.
    The problem is that I didn't find a counter that create the particle quickly enough. For example, I tried:

    counter = new KeyDownTrigger(new Blast(1), _stage);
    I thought this would create my particle every time, it just doesn't work.

    counter = new KeyDownTrigger(new Steady(1), _stage);
    This creates my particle but after a certain amount of time.

    counter = new KeyDownTrigger(new Pulse(0.1, 1), _stage);
    This is kind of closer, the particle is created when I key down but also repeated if I hold the key which is not what I want.

    I'm not sure this is the right way to achieve what I need anyway.

    2. add particle on the fly

    My other idea was to create a zero counter, and somehow add the particle on the fly.

    I would do something like"

    counter = new ZeroCounter();

    Then start the emitter:


    and add the particle on a key down event:

    var p:Particle2D = new Particle2D();
    p.image = new DummyLetterForTest(); // movieclip
    _emitter.addParticle(p, true);

    But, I can't get anything working like this.

    Could someone give a hint how to achieve the following:

    - create emitter
    - start emitter (emitter does nothing yet)
    - when user press a key:
    --> add particle to emitter (particle that reference the sprite of the letter)
    --> update the TweenToZone point to a new point I've calculated
    --> the emitter apply the motion on any particle added

    I hope what I want to do is kind of clear...

    Any help/hint would be greatly appreciated!


    • CommentAuthorromu
    • CommentTimeSep 1st 2011
    Hi again,

    Here is what I've done to solve my problem:

    - user press a key, get the char code
    - create a new emitter with a Blast(1) and a Sprite that draws the corresponding letter, or use one already created (the emitters are stored in a dictionary with the char code as a key)
    - call start on the emitter corresponding at the char code

    It is very simple and it works, I have to create a certain amount of emitters though.
    It looks like Flint is not that flexible when it comes to update, add or remove particles (unless I'm missing something), but I can understand why.

    If someone has a better solution, I'd be curious to hear about it.

    • CommentAuthorRichard
    • CommentTimeSep 28th 2011
    Hi Romu

    There was an error in Flint, which I've now fixed in the git repository and will be in the next release. If you grab the latest code this should work now...

    var p:Particle2D = new Particle2D();
    p.image = new DummyLetterForTest();
    _emitter.addParticle(p, true);
    • CommentAuthorGeorge.M
    • CommentTimeApr 19th 2012 edited
    I am working on something quite similar, where I want to add more particles as something is charging up and more 'excitement' is displayed.

    My main class contains:

    public function initialize () : void {
    _emitter = new Charge(); //

    _p = new Particle2D();
    _p.image = new Sparkle(); // a MovieClip
    _emitter.addParticle(_p, true);

    var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
    renderer.addEmitter( _emitter );
    addChild( renderer );

    _emitter.start( );

    public function progress (value:int) : void {
    _emitter.addParticle(_p, true);

    the emitter:

    public class Charge extends Emitter2D
    public function Charge()
    counter = new ZeroCounter();

    addInitializer( new Position( new RectangleZone( 10, 10, 680, 480 ) ) );
    addInitializer( new Velocity( new DiscZone( new Point( 0, 0 ), 150, 100 ) ) );

    addAction( new RotateToDirection() );
    addAction( new BoundingBox( -25, 0, 770, 1200 ) );
    addAction( new Move() );

    Unfortunately no new particles are added, yet the one that does remain speeds up each time addParticle is called.
    Swapping the counter for Blast(1) and adding in addInitializer( new ImageClass( Sparkle ) ); results in the effect I am looking for where there is a a new particle added.

    But as more particles are added older ones freeze and fail to move any more.

    Can anyone help?
    • CommentAuthorRichard
    • CommentTimeApr 19th 2012
    Hi George

    It looks to me like you only create one particle - _p - at the start of the code, and then keep adding that same particle. If you want multiple particles, you need to create a new particle each time. Try

    public function progress (value:int) : void {
    var _p : Particle2D = new Particle2D();
    _p.image = new Sparkle();
    _emitter.addParticle(_p, true);