Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthorfred
- CommentTimeJun 10th 2011
Hello, I am trying to display 2 shapes from the library using InitializerGroup. I can only see 1 at the time... don't know what I am doing wrong :(
var AppleInitializer:InitializerGroup = new InitializerGroup();
AppleInitializer.addInitializer( new SharedImage( new Apple()));
AppleInitializer.addInitializer( new ScaleImageInit(0.1, 0.3));
AppleInitializer.addInitializer( new Position( new RectangleZone( 0, 0, 1000, 500)));
var MickeyInitializer:InitializerGroup = new InitializerGroup();
MickeyInitializer.addInitializer( new SharedImage ( new Mickey()));
MickeyInitializer.addInitializer( new ScaleImageInit(0.1, 0.3));
MickeyInitializer.addInitializer( new Position( new RectangleZone( 0, 0, 1000, 500)));
emitter = new Emitter2D();
emitter.counter = new Blast(1);
renderer = new BitmapRenderer( new Rectangle ( 0, 0, 1000, 500));
emitter.addInitializer( new ChooseInitializer ( ([MickeyInitializer, AppleInitializer])) );
addChild(renderer);
renderer.addEmitter(emitter);
emitter.addInitializer( new Velocity ( new DiscZone (new Point (25, 25), 100)));
emitter.addAction( new WrapAroundBox(-100, -100, 1100, 700));
emitter.addAction( new Move());
emitter.start();
it does work if I use: emitter.counter = new Steady(1);
Thx for your help.
fred -
- CommentAuthorRichard
- CommentTimeJun 13th 2011
Your counter, Blast(1), indicates you only want one particle. If you want to see both shapes you'll need to create more particles. e.g.emitter.counter = new Blast( 100 ); -
- CommentAuthorfred
- CommentTimeJun 13th 2011
Hey Richard,
Thanks for your help.
I guess I am not sure how to program what I am trying to do:
I don't want 100 particles. I have 5 different shapes that I pulled from the library and I want to show only those 5 objects and use Flint to create interaction between them (like MutualGravity, Approach Neighbours etc ) ... Should I use 5 emitters?
Thanks again.
fred -
- CommentAuthorRichard
- CommentTimeJun 13th 2011 edited
You could create a custom initializer to set the particles' images to each of the five shapes, and set the counter to a blast with a count of 5.
Or, create instances of the five shapes and use the createParticles2DFromDisplayObjects method to create particles from them. -
- CommentAuthorfred
- CommentTimeJun 14th 2011
Hey Richard,
Thanks a lot for your help. I managed to make it work :)
I had to add an EventListener on "particleAdded" to start the emitter. If not, I get this error:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at org.flintparticles.twoD.renderers::DisplayObjectRenderer/addParticle()[/actionScript/org/flintparticles/twoD/renderers/DisplayObjectRenderer.as:97]
at org.flintparticles.common.renderers::SpriteRendererBase/particleAdded()[/actionScript/org/flintparticles/common/renderers/SpriteRendererBase.as:151]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at org.flintparticles.common.emitters::Emitter/createParticle()[/actionScript/org/flintparticles/common/emitters/Emitter.as:661]
at org.flintparticles.common.emitters::Emitter/start()[/actionScript/org/flintparticles/common/emitters/Emitter.as:831]
So, here is the code:
public function CreateParticles()
{
emitter = new Emitter2D();
var renderer:DisplayObjectRenderer = new DisplayObjectRenderer ();
addChild(renderer);
renderer.addEmitter(emitter);
////// These are assets in a swc file:
var myApple:Apple = new Apple();
var myMickey:Mickey = new Mickey();
var myCoca_cola:Coca_cola = new Coca_cola();
var myMac_Donalds:Mac_Donalds = new Mac_Donalds();
var myMarlboro:Marlboro = new Marlboro();
var myNike:Nike = new Nike();
var myArray:Array = [myApple, myMickey, myCoca_cola, myMac_Donalds, myMarlboro, myNike];
emitter.addInitializer( new Position( new RectangleZone( 0, 0, 1000, 500)));
emitter.addInitializer( new Velocity ( new DiscZone (new Point (25, 25), 10)));
emitter.addInitializer( new ScaleImageInit( 0.1, 0.2 ));
emitter.addAction( new WrapAroundBox(-100, -100, 1100, 600));
emitter.addAction( new Move());
emitter.addAction( new ApproachNeighbours(500, 10));
var myParticles:Vector.<Particle> = Particle2DUtils.createParticles2DFromDisplayObjects( myArray );
emitter.addEventListener("particleAdded", particleHandler);
emitter.addParticles( myParticles , true);
emitter.counter = new Blast(6);
//////// This creates an error >>> emitter.start();
}
protected function particleHandler(event:ParticleEvent):void
{
emitter.start();
} -
- CommentAuthorRichard
- CommentTimeJul 15th 2011
Try removing the blast counter. You don't want to create more particles, you've already created the six particle you need with this codevar myParticles:Vector.<Particle> = Particle2DUtils.createParticles2DFromDisplayObjects( myArray );
emitter.addParticles( myParticles , true);
That should remove the error. -
- CommentAuthorMichaeljohn
- CommentTimeMar 13th 2013 edited
Oaky,I like this
___________________________________________________
Diablo 3 Gold|Buy Diablo 3 Gold|Buy Wow Gold|D3 Gold
1 to 7 of 7
