Flint Particle System Forum - Cloning Particles2010-12-25T19:38:17+00:00http://flintparticles.org/forum/
Lussumo Vanilla & Feed Publisher
Cloning Particleshttp://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=628#Comment_6282009-01-16T12:19:45+00:002010-12-25T19:38:17+00:00Owen Bennetthttp://flintparticles.org/forum/account.php?u=140
Is there currently a way to clone a particle? I've implemented my own quick and dirty solution using a helper class with a couple of static methods, but this has some speed implications, especially ...
Here's the code I'm using:
// creates a clone of the specified particle, attaches it to the emitter and then returns the new particle public static function cloneParticle(emitter:Emitter, particle:Particle):Particle { var p2:Particle = emitter.particleFactory.createParticle(); emitter.addExistingParticles([p2], true);
mirrorParticle(particle, p2);
return p2; }
// copies all of the properties of particle1 to particle2 public static function mirrorParticle(particle1:Particle, particle2:Particle, excludedProperties:Array = null):void { if (excludedProperties == null) excludedProperties = ["sortID", "image"]; else excludedProperties.push("sortID", "image");
var description:XML = describeType(particle2);
var varList:XMLList = description..variable;
for each (var item:XML in varList) { if (excludedProperties.indexOf(String(item.@name)) != -1) continue;
var prop:Object = particle1[item.@name];
if (prop is Number || prop is String || prop is Boolean) particle2[item.@name] = prop; } }]]>
Cloning Particleshttp://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=631#Comment_6312009-01-18T10:55:38+00:002010-12-25T19:38:17+00:00Richardhttp://flintparticles.org/forum/account.php?u=1
Now you mention it, it seems so obvious. So I've added a clone method to the Particle class. This clones the image property along with everything else - if particles are used with a BitmapRenderer ...
Cloning Particleshttp://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=634#Comment_6342009-01-19T11:03:09+00:002010-12-25T19:38:17+00:00Owen Bennetthttp://flintparticles.org/forum/account.php?u=140
Thanks for adding this Richard. The thing with the DisplayObjectRenderer image is a bit of a problem - they way I got around it was to let the emitter create the image when adding the particle. ...
if (image is IClonable) p.image = image.clone(); else p.image = image;
Obviously this may be a lot of work to implement...
Other than that, how would it be possible to create a copy of a DO image? I can't think of a neat way to do it that doesn't require knowledge of the parameters that were put into the emitter initialiser.]]>
Cloning Particleshttp://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=636#Comment_6362009-01-20T14:10:53+00:002009-01-20T14:12:18+00:00Richardhttp://flintparticles.org/forum/account.php?u=1
Unfortunately, people use other display objects too - display objects created in flash for example - so it's not possible to expect a clone method for images, although it's theoretically possible ...
I did some very extensive tests to try to find a way to clone a display object, but even the ByteArray method doesn't work with display objects. So it seems there isn't a way, although it may be possible with reflection and a lot of code.]]>