Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthored
- CommentTimeOct 20th 2009 edited
I've learned from the tutorial that the emitters must create the particles to be rendered using either the DisplayObjectRenderer or BitmapRenderer. But I haven't seen an example much discussion about defining an image from a separate class file for use with the ImageClass when passing the emitter your image. For example, I have a class called Box.as that extends a MovieClip and generates a black box whose height and width are linked to the length of a sentence that is stored in a database. After the data has been loaded, the length of the sentence is passed to each Box as a parameter; within each Box are various MouseEvents.
I'm trying to use ImageClasses to "load" an array of MovieClips.
//PHP loaded, XML nodes converted to object properties...
private function dataLoaded(e:DataEvent):void {
_itemArray = e.items;
for (var i:uint = 0; i < _itemArray.length; i++) {
var box:Box = new Box(_itemArray[i].sentence.length);
_boxArray.push(box);
}
images = new ImageClasses(_boxArray);
emitter.counter = new Blast(_boxArray.length);
emitter.addInitializer(images);
emitter.addInitializer(new Position(zone));
renderer.addEmitter(emitter);
renderer.mouseChildren = true;
addChild(renderer);
}
But I keep getting this error:Error #1034: Type Coercion failed: cannot convert Box@35537451 to Class.
I've compared my code to the snippet seen here: http://flintparticles.org/forum/comments.php?DiscussionID=242&page;=1 but I still get the error...any ideas? -
- CommentAuthored
- CommentTimeOct 20th 2009 edited
Solution found :)
Took a hint from this post: http://flintparticles.org/forum/comments.php?DiscussionID=155. I placed the particle first, then added them to the emitter...I'm guessing I could have placed the particles after adding them as well, but this seemed the most straightforward to me.
private function dataLoaded(e:DataEvent):void {
_itemArray = e.items;
for (var i in _itemArray) {
var l:uint = _itemArray[i].sentence.length;
var box:Box = new Box(l);
box.x = 900 * Math.random() + 50;
box.y = 550 * Math.random() + 25;
addChild(box);
box.setData(_itemArray[i]);
_boxArray.push(box);
var particle = Particle2DUtils.createParticle2DFromDisplayObject(box, renderer, emitter.particleFactory);
emitter.addExistingParticles([particle], true);
}
emitter.addInitializer(new Position(zone));
emitter.addAction(new MutualGravity(5, 500, 3));
emitter.addAction(new TurnTowardsMouse(.25, renderer));
emitter.addAction(new BoundingBox(0, 0, 1000, 600));
emitter.addAction(new SpeedLimit(150));
emitter.addAction(new Move());
renderer.addEmitter(emitter);
renderer.mouseChildren = true;
addChild(renderer);
emitter.start();
emitter.runAhead(10);
}
BTW, Richard, thank you for this remarkable system. You've really made particle simulation accessible to everyone. Amazing documentation as well. Hats off to you! -
- CommentAuthorRichard
- CommentTimeNov 2nd 2009
Hi Ed
I'm pleased you found the solution. It is possible to pass the image directly to the particle -particle.image = box
but because the emitter works with behaviours, you'd have to wrap this up as an Initializer.
I intend to add a tutorial about writing custom Initializers and Actions soon, but there's a few bits of work I have to get out the way first.
Richard
1 to 3 of 3
