Flint Particle System Forum - Cloning Particles Sun, 13 Jun 2010 08:59:55 +0100 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.4 & Feed Publisher Cloning Particles http://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=628#Comment_628 http://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=628#Comment_628 Fri, 16 Jan 2009 12:19:45 +0000 Owen Bennett
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 Particles http://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=631#Comment_631 http://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=631#Comment_631 Sun, 18 Jan 2009 10:55:38 +0000 Richard Cloning Particles http://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=634#Comment_634 http://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=634#Comment_634 Mon, 19 Jan 2009 11:03:09 +0000 Owen Bennett
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 Particles http://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=636#Comment_636 http://flintparticles.org/forum/comments.php?DiscussionID=156&Focus=636#Comment_636 Tue, 20 Jan 2009 14:10:53 +0000 Richard
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. ]]>