-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FlxSpriteGroup alpha=0 problem #1353
Comments
I've found a solution here: #701 So in my example:
is now working, but still it's a bit weird having to restore the FlsSpriteGroup alpha like that. |
After reading the previous thread, I'm definitely with the "just document it" approach, that stuff is complicated. |
@Txori I recommend you use spriteGroup.forEach(function(s)
{
s.alpha = sprite.alpha;
}); |
All right, thank you. |
Would it make sense to include the for each in the spriteGroup.alpha setter? |
Yes, I think that would be a good solution. |
I can do this tonight, but do we want the group's setter to set the child's alpha or be multiplied by its true alpha? The latter requires a separate |
Sorry for the late response. I talked about it with a friend and we come to the conclusion that multiplied by its true alpha is the better solution. It would avoid errors like sprites in the group that becomes visible although they should not, because of their individual alpha settings. |
Maybe something like // FlxSpriteGroup.hx
inline function multAlphaTransform(...) {
if (Alpha == 0) Sprite.oldAlpha = Sprite.alpha;
Sprite.alpha *= Alpha;
}
inline function divAlphaTransform(...) {
if (Alpha == 0) Sprite.alpha = Sprite.oldAlpha;
else Sprite.alpha /= Alpha;
} Where multAT is used in This directly sets the child sprite's alpha which I'm not a big fan of, but the alternative is to change every instance of Suggestions? |
OK, but what about cases like in #1870? For example, you fade out a flxspritegroup, and then go to fade it back in--nothing happens, because after fading out, all of its children were alpha=0. I think having a relative alpha would be a nice idea. Just like how the volume mixer on Windows works--as you raise/lower the master volume, all the other volumes move relative to it. But they don't suddenly stick at 0 just because you hit 0 with the master at one point. |
If we end up having a relative alpha, would it make sense to also make position, rotation, etc that way? To where there's an internal The setter would have to just affect the internal var and also set the |
That'd be cool. Add |
+1 When setting the alpha in a FlxSpriteGroup it should set each child's alpha to the same value in my opinion. Regardless the current interaction is weird and inconsistent as it allows FSGroup.alpha = 0 to work, but not FSGroup.alpha = 1. |
@MSGhero and actually it should be parent * child, not parent + child, I guess. The only problem is, FlxSprite has no notion of "parent," and a side effect of that is, there's nothing stopping a sprite from having multiple parent groups. There was some discussion in another thread, IIRC, of merging the two concepts, so sprites were just nestable. That would make this issue a lot easier to solve. |
The consensus in a random chat on Discord was that FSG should have some override public function set_alpha(f:Float):Float {
if (f == 0) {
alphaHack = true;
f = 0.000000001;
visible = false;
}
// etc
}
override public function get_alpha():Float {
if (alphaHack) return 0;
return _alpha;
} |
override public function set_alpha(value:Float):Float {
if (value > 0) {
visible = true;
return this.alpha = value;
}
visible = false;
return this.alpha = 0.001;
}
override public function get_alpha():Float {
return this.alpha;
} Given the current implementation, I think that's the cleanest solution. I don't know if it's worth creating an internal variable for this. If you really wanted to have the get return 0 then you could just use override public function get_alpha():Float {
return (this.visible) ? this.alpha : 0;
} |
Whenever you set the FlxSpriteGroup alpha to 0, it wont show up again when you change its alpha after that, unlike the FlxSprite...
Here's the snippet:
I've only tried on Flash and Neko.
And here's my halelib version:
The text was updated successfully, but these errors were encountered: