Flint Particle System Forum - add particle on keydown 2016-05-08T00:41:02+01:00 http://flintparticles.org/forum/ Lussumo Vanilla & Feed Publisher add particle on keydown http://flintparticles.org/forum/comments.php?DiscussionID=514&Focus=1713#Comment_1713 2011-09-01T18:47:53+01:00 2016-05-08T00:41:02+01:00 romu http://flintparticles.org/forum/account.php?u=538 Hi, 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 ... 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.

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

Actions:
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:

_emitter.start();

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!

Thanks.

Romu]]>
add particle on keydown http://flintparticles.org/forum/comments.php?DiscussionID=514&Focus=1714#Comment_1714 2011-09-01T22:40:44+01:00 2016-05-08T00:41:02+01:00 romu http://flintparticles.org/forum/account.php?u=538 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 ...
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.

Romu]]>
add particle on keydown http://flintparticles.org/forum/comments.php?DiscussionID=514&Focus=1733#Comment_1733 2011-09-28T09:03:27+01:00 2016-05-08T00:41:02+01:00 Richard http://flintparticles.org/forum/account.php?u=1 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 ...
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);
]]>
add particle on keydown http://flintparticles.org/forum/comments.php?DiscussionID=514&Focus=1908#Comment_1908 2012-04-19T16:01:28+01:00 2012-04-19T16:16:27+01:00 George.M http://flintparticles.org/forum/account.php?u=478 Hi, 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 ... 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?]]>
add particle on keydown http://flintparticles.org/forum/comments.php?DiscussionID=514&Focus=1909#Comment_1909 2012-04-19T22:32:15+01:00 2016-05-08T00:41:02+01:00 Richard http://flintparticles.org/forum/account.php?u=1 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 ...
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);
}
]]>