AdamAtomic/flixel — Issue #219: Alpha changing incorrectly
Author: mouseas
Created: 2012-01-17 06:11:12+00:00
State: open

I have the following code in a FlxSprite:

override public function update():void {
lifespan += FlxG.elapsed;

if (lifespan > 3) { // 3 seconds before starting fade
alpha = (1 - ((lifespan - 3) / 15)); // <--- this line...fade slowly over 15 seconds

}

if (alpha < 0.01) {
State.s.remove(this, true);
}
super.update();
}

Instead of taking 15 seconds to fade out, the sprite fades out in less than a second. I took a quick poke into the alpha-related code in FlxSprite, and it looks like alpha is adjusted in discrete increments. Problem is, if the amount the alpha is supposed to change is too small, it still drops it one increment. The end result? The FlxSprite is invisible when its alpha value is actually at around 0.95 - 95% opaque, i.e. ever-so-slightly see-through.