Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthorFlashDev2007
- CommentTimeJan 27th 2011 edited
Recently I needed to eject particles from a bottle and have them go behind a logo and then fall back in front of it. I decided to extend the renderer to handle the children on the display list. Thought I would share it with you, any feedback on my approach appreciated.
I made a small donation, cheers to you Richard...
package
{
import flash.display.DisplayObject;
import flash.geom.ColorTransform;
import org.flintparticles.twoD.particles.Particle2D;
import org.flintparticles.twoD.renderers.DisplayObjectRenderer;
public class MultipleDisplayObjectRenderer extends DisplayObjectRenderer
{
protected var image:DisplayObject;
public function MultipleDisplayObjectRenderer()
{
super();
}
public function addImage(img:DisplayObject):void
{
image = img;
addChild(image);
}
override protected function renderParticles( particles:Array ):void
{
var particle:Particle2D;
var img:DisplayObject;
var len:int = particles.length;
for( var i:int = 0; i < len; ++i )
{
particle = particles[i];
img = particle.image;
img.transform.colorTransform = particle.colorTransform;
img.transform.matrix = particle.matrixTransform;
// if the particle is at half life, and its index is lower than the image swap em over
if(particle.age > particle.lifetime * 0.5 && getChildIndex(img) < getChildIndex(image))
{
swapChildren(image, img);
}
}
}
}
} -
- CommentAuthorRichard
- CommentTimeFeb 3rd 2011
Thank you. I've been asked about this before - now here's some code I can point users to.
1 to 2 of 2
