Author Topic: FlxEmitter should handle changes in its members while emitting  (Read 1158 times)


  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
As it stands, when a FlxEmitter has the length of its members Array changed while the FlxEmitter is emitting, a few things can happen:

  • If it was lengthened:
    • If the element gets push()ed to the end of the array, no harm done. emitParticle() will emit it when it reaches that point in the Array, unless it was already at the end of the Array and just reset, in which case the element won't get emitted until the next pass.
    • If the element was unshift()ed, emitParticle() will reemit the particle it just emitted on the next call of emitParticle() - usually harmless, but if there is a custom group of particles that needs to come out in a particular order, this is not desirable.
  • If it was shortened:
    • If the element was pop()ed, emitParticle() will either work just fine, not emitting that element, or, if it was just about to emit that element, there will be an error #1009 (null reference error). AKA, crash.
    • If the element was unshift()ed, the element that the emitter was about to emit gets skipped, or if the emitter is at the end of the premodification array, another #1009 results.
  • If it was changed with slice() or splice(), any combination of the above issues can result, depending on what exactly you did to it.

An improvement to this relatively new feature would be if FlxEmitter listened for changes to its members array (easy enough to do with getters and setters) and adjusted the _particle uint member accordingly. I am unsure, however, as to how to check _which_ element in the Array was changed, which is needed information to do this.

If I turn out to not be the only one who wants this improvement, I can make changes to my copy of FlxEmitter and see if I make any progress.

EDIT: A simple change that will prevent #1009's is below. When _particle exceeds the bounds of the members Array, it will reset _particle to 0. Add these after the line that reads "_counter++;" in emitParticle()
Code: [Select]
if (_particle >= members.length)
_particle = 0;
« Last Edit: Thu, Jun 24, 2010 by thecodebot »