Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm working with Flixel and attempting to emit "custom" FlxParticles from a FlxEmitter. However, my main issue is that I typically get the default Flixel image emitted instead of my custom graphic.

If I modify the FlxParticle constructor in the Flixel source code like so:

public function FlxParticle()
{
    super();
    lifespan = 0;
    friction = 500;
    makeGraphic(4, 4, 0xFFFFFFFF);
}

I can get a custom particle (a 4 x 4 white square) to emit from my FlxEmitter.

However, if I write my own class that extends FlxParticle like so:

public class EffectParticle extends FlxParticle
{
    public function EffectParticle()
    {
        super();
        makeGraphic(4, 4, 0xFFFFFFFF);
    }
}

That class won't work - I will get the default Flixel image instead of my tiny white square. I similar thing happens if I just call "makeGraphic()" on a FlxParticle variable.

Why does this happen, and other than modifying Flixel's source code or loading in custom graphic (from an embedded image), how can I create my custom particles?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

You have to be sure to specify the number of particles in the third parameter of the FlxEmitter.

If you don't do this, it will ignore your particles and use the default.

Also, set the lifespan in emitter.start(), not elsewhere, otherwise it won't work.

At least, this is all true at the end of 2011 ...

e.g.

var emitter:FlxEmitter = new FlxEmitter(100, 100, 100);

for (i = 0; i < 100; i++) { emitter.add(new ExplosionParticle()); }

add(emitter); emitter.start(true, 1);

share|improve this answer
    
Specifying the number of particles (Size parameter) in the FlxEmitter constructor solved the problem. –  pikejd Jan 15 '12 at 17:28

Your code looks right, so here's some things to try to help debug this:

  1. Try using an image and loadGraphic(). Does this work?

  2. Try extending FlxSprite instead of FlxParticle and see if makeGraphic isn't working for FlxSprite either.

  3. What are you seeing on the screen when the particles are emitted? If you're only making one instance of your custom particle to test, I wonder if you're actually seeing the particle emitter, and are forgetting to add(EffectParticle) to your FlxState?

Can you show us the code from your FlxState or wherever the emitter and particles are being added/generated? That might help to find the problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.