Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthorMakoto
    • CommentTimeAug 29th 2011
     
    I found that I could create an animated particle using a MovieClip with a series of frames containing the animation along with the displayObjectRenderer. Now while this works, I fear that it could get too computationally expensive (especially in a game where many other things are happening) and started looking into a way to get the particles to use an array of BitmapData objects as I believe the performance would be better, however I am unsure of exactly how to achieve this. Anyone have an idea?
    • CommentAuthorRichard
    • CommentTimeAug 30th 2011
     
    You'll need to customise the renderer to do this, but it shouldn't be too difficult. Take a look at the source code for the BitmapRenderer class, in particular the drawParticle method. You could create a custom renderer by extending the BitmapRenderer and overriding the drawParticle method (you shouldn't need to touch any other methods). The image property of the particle can be any object so make it a custom bitmap animation class and draw the current frame, and step to the next frame, in the drawParticle method of your renderer.
    • CommentAuthorMakoto
    • CommentTimeAug 30th 2011
     
    I'm assuming by your response that I'm correct in assuming that this method of animated particles will indeed be faster than the MovieClip route, yes?
    Also, another reason I'm trying this method is that my animation is derived from a sprite sheet that I divide up into BitmapData objects at runtime via copyPixels.
    My intent here is to get the fastest possible method of rendering animated particles and am wondering if this route will provide a definite speed increase.
    My attempts thus far have been at the particle level where I was using the the emitter's EMITTER_UPDATED event to step each particle's animation but haven't really noticed a speed increase.
    I'll give your method a go but wouldn't it be faster to just draw the BitmapData directly to the canvas and bypass code that has to manage another object?
    • CommentAuthorMakoto
    • CommentTimeAug 31st 2011
     
    Well here's the modification I came up with and it seems to faster than my other attempts.
    I basically pass an Object of arrays containing the BitmapData sequences to the Renderer and use the particle's dictionary to hold total frames, current frame, and type (a reference to which animation sequence in the Object passed into the Renderer).
    I don't know for sure if this increases performance or not but it seems in theory that it should.

    package org.flintparticles.twoD.renderers
    {
    import org.flintparticles.twoD.particles.Particle2D;

    import flash.geom.Rectangle;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.display.DisplayObject;

    public class AnimatedBitmapRenderer extends BitmapRenderer
    {
    private var _bitmaps:Object;

    public function AnimatedBitmapRenderer( canvas:Rectangle, BMDs:Object, smoothing:Boolean = false )
    {
    super( canvas, smoothing );
    _bitmaps = BMDs;
    }

    override protected function drawParticle( particle:Particle2D ):void
    {
    var image = particle.image;
    var matrix:Matrix;
    if(particle.dictionary.TYPE){
    particle.dictionary.CFRAME++;
    if(particle.dictionary.CFRAME > particle.dictionary.FRAMES) particle.dictionary.CFRAME = 0;

    matrix = new Matrix();
    matrix.translate( -(_bitmaps[particle.dictionary.TYPE][0].width * 0.5), -(_bitmaps[particle.dictionary.TYPE][0].height * 0.5) );
    matrix.rotate(particle.rotation);
    matrix.scale(particle.matrixTransform.a, particle.matrixTransform.d);
    matrix.translate( particle.matrixTransform.tx, particle.matrixTransform.ty );

    image = _bitmaps[particle.dictionary.TYPE][particle.dictionary.CFRAME];
    } else {
    matrix = particle.matrixTransform;
    }
    matrix.translate( -_canvas.x, -_canvas.y );
    _bitmapData.draw( image, matrix, particle.colorTransform, DisplayObject( particle.image ).blendMode, null, _smoothing );
    }
    }
    }
    • CommentAuthorRichard
    • CommentTimeSep 27th 2011
     
    Hi Makoto

    Thank you for sharing this.

    Richard