You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
override public function update():void {
// Here is my +1 error, the last time this branch is true, it sets the frame one past the end of the spritesheet.
if (frame < frames) {
frame = frame + 1;
trace(frame);
}
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.
Edit: I was able to isolate the problem quite a bit. It was trying to fade on a non-existant frame (thanks to a +1 error on my part), ie the frame it was currently on was a copy of the last frame. I tried using makeGraphic() and the same bug happened. Basically, this bug occurs when the graphic is unique and there's no sprite/spritesheet to reference back to. If the frame is a valid image on a spritesheet, this bug does not occur.
Expected behavior: Sprite fades slowly, based on alpha value.
Actual behavior: If sprite graphic is unique, it fades quickly. The change in actual transparency is not in line with the alpha value.
To reproduce:
Create a sprite and either (a) use makeGraphic() and possibly some draw methods to create a unique graphic, or (b) load an animated spritesheet and set the frame outside the range of existing frames.
Adjust the alpha of the sprite slowly over many frames. Display the numeric alpha value somewhere for comparison; the alpha value should be much higher than the sprite's visibility.
For comparison, use an existing frame or the default image, and adjust the alpha slowly as before. This time the alpha value matches the sprite's visibility.
The text was updated successfully, but these errors were encountered:
Did a little more poking. My guess is that when the bug does occur, the graphic has alpha applied, and the alpha-applied version is assigned to the graphic's place. Thus each frame the alpha is adjusted, the graphic becomes that much more transparent.
I have the following code in a FlxSprite:
override public function update():void {
// Here is my +1 error, the last time this branch is true, it sets the frame one past the end of the spritesheet.
if (frame < frames) {
frame = frame + 1;
trace(frame);
}
}
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.
Edit: I was able to isolate the problem quite a bit. It was trying to fade on a non-existant frame (thanks to a +1 error on my part), ie the frame it was currently on was a copy of the last frame. I tried using makeGraphic() and the same bug happened. Basically, this bug occurs when the graphic is unique and there's no sprite/spritesheet to reference back to. If the frame is a valid image on a spritesheet, this bug does not occur.
Expected behavior: Sprite fades slowly, based on alpha value.
Actual behavior: If sprite graphic is unique, it fades quickly. The change in actual transparency is not in line with the alpha value.
To reproduce:
The text was updated successfully, but these errors were encountered: