Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
How do I?: Help with my code for making an emitter follow a movieclip on stage
Bottom of Page1 to 4 of 4
-
- CommentAuthorawesomerami
- CommentTimeDec 30th 2008 edited
Hi Richard and everyone on this forum. I'm a beginner with Flint and i think it's an awesome particle system with enormous potential.
I would appreciate it immensely if i could get some feedback on my code for getting an emitter (some stars) to follow a movieclip (called fly_mc) on stage. It seems that i managed successfully to pull it off, just the frame rate dies after a few seconds.
I created my own custom class from MoveEmitter.as and called it EmFollowMc.as
Here is the code for EmFollowMc.as:package org.flintparticles.twoD.activities
{
import org.flintparticles.common.activities.ActivityBase;
import org.flintparticles.common.emitters.Emitter;
import org.flintparticles.twoD.emitters.Emitter2D;
import flash.display.DisplayObject;
public class EmFollowMc extends ActivityBase
{
private var _mcname:DisplayObject;
public function EmFollowMc ( image:DisplayObject )
{
_mcname = image;
}
override public function update( emitter : Emitter, time : Number ) : void
{
var e:Emitter2D = Emitter2D( emitter );
e.x = _mcname.x;
e.y = _mcname.y;
}
}
}
And now the code in the first frame of my timeline:var emitter:Emitter2D = new Emitter2D();
emitter.counter = new Steady(10);
emitter.addInitializer( new ImageClass( Star, 5 ) );
emitter.addInitializer( new Position( new RectangleZone( 100,100,160,160) ) );
emitter.addInitializer( new Lifetime( 1, 2 ) );
emitter.addAction( new Move() );
emitter.addAction( new Age() );
emitter.addActivity( new EmFollowMc (fly_mc));
var renderer:DisplayObjectRenderer = new DisplayObjectRenderer;
renderer.addEmitter( emitter );
addChild( renderer );
emitter.start( );
I'm manually tweening the fly_mc movieclip across the stage and the particles follow nicely. It's just that the frame rate commits suicide after just a couple of seconds, and it's only a Steady(10).
Thanks for taking the time to read this and i hope i've posted this in such a way that makes it easy to interpret. Thanks again. -
- CommentAuthorRichard
- CommentTimeJan 7th 2009
I can't see any problems in the code you've posted. What happens if you don't tween fly_mc but keep everything else the same? -
- CommentAuthornotsuj
- CommentTimeDec 18th 2010
I am digital artist now using flash every day and I need to be able to integrate particles into my workflow. I have been using Flint for the last couple days getting familiar with the basics of emitters and particles. I have used the code above and added EmFollowMc to the flint library and imported it into my test FLA. I am trying to replicate the situation above without success. I need particles to emit from a movie clip which has a motion guide directing it via the motion editor.
The EmfollowMc.as file is the same as above and in the right spot. Below is the code from frame #1 (same as above):
--------------
import org.flintparticles.common.counters.*;
import org.flintparticles.common.displayObjects.RadialDot;
import org.flintparticles.common.initializers.*;
import org.flintparticles.twoD.actions.*;
import org.flintparticles.twoD.emitters.Emitter2D;
import org.flintparticles.twoD.initializers.*;
import org.flintparticles.twoD.renderers.*;
import org.flintparticles.twoD.zones.*;
import org.flintparticles.twoD.activities.*;
addChild( new SnowBackground() );
var emitter:Emitter2D = new Emitter2D();
emitter.counter = new Steady(2);
emitter.addInitializer( new ImageClass( Star, 5 ) );
emitter.addInitializer( new Position( new RectangleZone( 100,100,100,100) ) );
emitter.addInitializer( new Lifetime( 1, 2 ) );
emitter.addAction( new Move() );
emitter.addActivity( new EmFollowMc (emitterMove));
var renderer:DisplayObjectRenderer = new DisplayObjectRenderer;
renderer.addEmitter( emitter );
addChild( renderer );
emitter.start( );
----------
I get this error:
1067: Implicit coercion of a value of type Class to an unrelated type flash.display:DisplayObject.
It is referring to this line: emitter.addActivity( new EmFollowMc (emitterMove).
The emitterMove mc is exported for AS. Again I am not a CS major, but if I can get this working, I can use it in my concept animations before they go to engineering for implementation into our custom software package. -
- CommentAuthorRichard
- CommentTimeDec 20th 2010
Sometime after the discussion above I added the FollowDisplayObjectactivity to Flint.
1 to 4 of 4
