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

    • CommentAuthorandrew2110
    • CommentTimeFeb 11th 2009
     
    Hi everybody,

    I'm getting started with using Flint 3D and would love to be able to use it for all the bullets and effects in an RTS game I'm writing for flash.

    I've started off by writing something that makes my sprites 'bleed' when they have been shot. The effect should come out at the angle the bullet entered the unit. After making something that roughly worked, I tried stress testing it and realised that I probably have done something very stupid as testing anymore than 15 - 20 bleeding units at once caused massive slow down.

    Anyway here's an example of what I've done so far (click on the movie to see the units bleed, and keep clicking to see the reaction angle changing) http://www.dukesbox.com/games/swfs/27/bleedExample.swf

    My code for this class is below.... Note that to cause a unit to bleed, there is a function named bleed().

    The big problems I see is that at the moment I dont know what I'm doing really so have a new sprite and new emitter for every single unit, and when theres going to be approximatley 200 units+ on a map, I thinkt it would be impossible to work on this way... If anyone has a few moments to look over my code and give me any advice, it would be very much appreciated

    package acs.particles
    {
    import org.flintparticles.common.actions.*;
    import org.flintparticles.common.counters.*;
    import org.flintparticles.common.displayObjects.Dot;
    import org.flintparticles.common.energyEasing.Quadratic;
    import org.flintparticles.common.events.EmitterEvent;
    import org.flintparticles.common.initializers.*;
    import org.flintparticles.twoD.actions.*;
    import org.flintparticles.twoD.emitters.Emitter2D;
    import org.flintparticles.twoD.initializers.*;
    import org.flintparticles.twoD.renderers.*;
    import org.flintparticles.twoD.zones.*;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.display.*;
    import flash.filters.*;

    public class CParticlesBleed extends Emitter2D
    {
    public var iLayer;
    var renderer:BitmapRenderer;
    public function CParticlesBleed(aComplexity,aXPos,aYPos,aStage)
    {
    iLayer = aStage.addChild(new Sprite());
    addInitializer( new Lifetime( 0.2, 0.3 ) );

    counter = new Blast( aComplexity );

    addInitializer( new SharedImage( new Dot( 2 ) ) );
    addInitializer( new ColorInit( 0xFF990000, 0xFF990000 ) );
    addInitializer( new Velocity( new LineZone( new Point(0,50 ),new Point(0,80) ) ) );
    addInitializer( new Lifetime( 0.9 ) );

    addAction( new Age( Quadratic.easeOut ) );
    addAction( new Move() );
    addAction( new Fade() );
    addAction( new Age() );

    counter = new Blast( aComplexity );

    //addAction( new Age( Quadratic.easeIn ) );

    renderer = new BitmapRenderer( new Rectangle( 0, 0, 750, 650 ) );
    renderer.addFilter( new BlurFilter( 2, 2, 1 ) );
    renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0 ] ) );
    renderer.addEmitter( this );
    iLayer.addChild( renderer );
    x = aXPos;
    y = aYPos;

    }
    public function end(e:EmitterEvent)
    {
    }
    public function bleed()
    {
    start();
    }
    }
    }
    • CommentAuthorRichard
    • CommentTimeFeb 13th 2009
     
    The biggest speed improvement would come from reducing the size of your BitmapRenderer canvas. Does it need to be 750 x 650 pixels?

    Alternatively, using a single renderer for all the emitters will also improve the speed.

    I notice that you have an end method - were you planning to use this to clean up the emitter when it's done. Something like

    addEventListener( EmitterEvent.EMITTER_EMPTY, end );

    public function end( e:EmitterEvent ):void
    {
    stop();
    iLayer.removeChild( renderer );
    renderer.removeEmitter( this);
    renderer = null;
    }


    Only the first two lines are strictly needed, the others just reinforce the point. This should enable the garbage collector to clean up your emitter and renderer (provided you don't have additional references to them) which will help.

    Finally, you could use some sort of object cache so you can reuse the emitters (see http://www.bigroom.co.uk/blog/object-pool-class for a generic object cache that I wrote a while back).
    • CommentAuthorandrew2110
    • CommentTimeFeb 19th 2009
     
    Just wanted to thankyou for your help with this richard. By making the Bitmap Renderer canvas a suitable size for each of the sprites it improved its performance massively.

    Also the object-pool-class is proving to be massively useful in other parts of the game when I'm looking at ways to do performance optimisation (particularly with reusage of projectile objects).

    If you have any interest in seeing your particle engine in an incredibly early version of my game at:

    http://www.dukesbox.com/games/game27.php

    Thanks again