@starry-abyss said in Necessary to remove off-screen FlxSprite instances?:
I believe the best way here is marking them
exists=false when off-screen and using
FlxTypedGroup<YourType> to create new sprites. Just don't forget to reset all variables of sprites to default values after recycling them (
reset() should be called automatically to reset velocity and stuff, but your own variables won't be reset).
I added an override for
reset(x, y) that resets all the variables of the sprite. But something's strange; could you please tell me if this behaviour is unexpected?
In my class constructors, I call
reset. This way, the construction code is common across the constructor and reset method.
For the first few objects, I can see HaxeFlixel calling
reset. But after a handful of objects, even though objects are being recycled, HaxeFlixel isn't calling
Is this how it's supposed to work? To work around this, I need to call
reset myself; newly-constructed objects get
reset called twice, but that seems to be a small price to pay.