Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthorRobC
- CommentTimeSep 13th 2010 edited
Hi, exscuse for my English,
I have this problem: I want to add a MouseEvent in this simple code just to trigger the particles movement:
[SWF(width="500", height="500", frameRate="60", backgroundColor="#000000")]
var emitter:Emitter2D = new Emitter2D();
var render:BitmapRenderer = new BitmapRenderer(new Rectangle(0, 0, 500, 500), true);
emitter.counter = new Blast(50);
emitter.addInitializer(new SharedImage(new RadialDot(4)));
emitter.addInitializer(new ColorInit(0xFF00FF00, 0x0000FFFF));
emitter.addInitializer(new Position(new RectangleZone(0, 0, 500, 500)));
emitter.addEventListener(MouseEvent.CLICK, movement);
function movement(e:MouseEvent) {
emitter.addInitializer(new Velocity(new RectangleZone(20, 0, 0, 20)));
emitter.addAction(new Move());
}
render.addEmitter(emitter);
addChild(render);
emitter.start();
I know that this addEventListener does nothing but I would know what is the right way.
Thank! -
- CommentAuthorUbuntu
- CommentTimeSep 14th 2010
I guess this does not work because the emitter is not a clickable sprite or movieclip. If you want this to work when you click anywhere on the stage then try using
stage.addEventListener(MouseEvent.CLICK, movement); -
- CommentAuthorRichard
- CommentTimeSep 16th 2010
Exactly. Use any clickable object to trigger the event, including the stage. The emitter is not clickable.
The particles can be made clickable -render.mouseEnabled = true;
render.mouseChildren = true;
render.addEventListener(MouseEvent.CLICK, movement); -
- CommentAuthorRobC
- CommentTimeSep 16th 2010 edited
Thank guys! But I tried with this code and nothing happens:render.mouseEnabled = true;
render.mouseChildren = true;
render.addEventListener(MouseEvent.CLICK, movement);
function movement(e:MouseEvent) {
emitter.addInitializer(new Velocity(new RectangleZone(20, 0, 0, 20)));
emitter.addAction(new Move());
}
I don't understand why.... -
- CommentAuthorRobC
- CommentTimeSep 16th 2010
Ok, I understand that I have to put theemitter.start()inside the function but, in this way, before the click there arent any particles on the stage.
What I want, if possible, is to start the movement of the particles when they are just on the stage.... -
- CommentAuthorRichard
- CommentTimeSep 16th 2010
Don't put the emitter.start() inside the function, but do put the emitter.addAction(new Move()) inside it. The particles won't move until you add this action to the emitter. -
- CommentAuthorRobC
- CommentTimeSep 16th 2010
I tried to leave out the function emitter.start() and just put the emitter.addAction(new Move()) inside it (like the example in my post before) but the particles doesn't move after the click. -
- CommentAuthorRichard
- CommentTimeSep 17th 2010
In your previous example, you should move the velocity initializer out of the function. Basically, you set the emitter up with all its initializers, including velocity. Then you start it, causing the particles to be initilized and so appear. Then when the click happens you add the move action, which causes them to move. -
- CommentAuthorRobC
- CommentTimeSep 17th 2010
Really thank you Richard!
Now is all ok, very good explanation!
1 to 9 of 9
