BitmapRenderer did not clean the canvas every frame

7 views
Skip to first unread message

rlavoie

unread,
Mar 29, 2010, 3:39:29 PM3/29/10
to Stardust Particle Engine
Hi,

I have made a small modification to the BitmapRenderer. It was not
cleaning the last frame properly.

override protected function render(e:EmitterEvent):void {
if (!targetBitmapData) return;

targetBitmapData.lock();
var particle:Particle2D;
var iter:ParticleIterator = e.particles.getIterator();
///////////////////////////////////////////////////////////////////////////////////////
/*** Clean canvas every frame*/
targetBitmapData.fillRect(targetBitmapData.rect, 0);
////////////////////////////////////////////////////////////////////////////////////////
while (particle = Particle2D(iter.particle)) {
var displayObj:DisplayObject = DisplayObject(particle.target);

var mat:Matrix = new Matrix();
mat.scale(particle.scale, particle.scale);
mat.rotate(particle.rotation * StardustMath.DEGREE_TO_RADIAN);
mat.translate(particle.x, particle.y);

targetBitmapData.draw(displayObj, mat, new ColorTransform(1, 1, 1,
particle.alpha), blendMode);

iter.next();
}
targetBitmapData.unlock();
}

Allen Chou

unread,
Mar 29, 2010, 8:21:42 PM3/29/10
to stardust-par...@googlegroups.com
Actually, that's an intentional design.

Sometimes you don't want to clean the bitmap every frame; instead, you could apply effects to the bitmap, such as color transformation or blur filters, as you can see in this example:

http://stardust-particle-engine.googlecode.com/svn/trunk/examples/2D/TurbulentPixels/TurbulentPixels.html

It's up to you to decide whether to clean the bitmap yourself after the Emitter.step() method call.
Reply all
Reply to author
Forward
0 new messages