5
\$\begingroup\$

I'm trying to "fadeIn" a store "screen" which is really just an invisible group. I set the group to visible=true, set the alpha to 0 and then do a "fadeIn" on the group. The problem is that the whole stage goes black (my clear screen color) and then fades back in.

storeGroup.addAction(Actions.sequence(Actions.alpha(0), Actions.fadeIn(1)));

I even went as far as to make the Table within my StoreGroup accessible and adding the action to that, but the result is the same.

storeGroup.getTable().addAction(Actions.sequence(Actions.alpha(0), Actions.fadeIn(1)));

Essentially I just want my store group to fade in over whatever is currently displaying, but the fade in seems to apply to every other actor in my Stage, not JUST the one I'm adding it to.

Any help would be greatly appreciated, I've been working on this all morning and can't figure out why the "fadeIn" is applying to everything.

\$\endgroup\$
  • \$\begingroup\$ Been playing around with this more. It looks like the other groups in the Stage are being hidden before the "Store" Group is fading in. I tried changing the glClearColor to white an noticed that it flashes white instead of black. Any idea why the rest of the Actors in the Stage are being hidden while my "Store" Group is being faded in? \$\endgroup\$ – Townsfolk Dec 22 '14 at 19:48
  • \$\begingroup\$ More information, I've narrowed it down to the alpha action. When I don't have the alpha action in a sequence action it seems to work on just the group. \$\endgroup\$ – Townsfolk Jan 4 '15 at 6:55
  • \$\begingroup\$ Isn't the same issue but a similar problem which for 2 stages, both fades when I try to add fade action on one of them, resolved by initializing individual SpriteBatch for each stage. \$\endgroup\$ – qua Apr 5 '15 at 22:57
  • 1
    \$\begingroup\$ Are you setting the batch's color based on the group's color (and subsequently its alpha) and not resetting the batch's color to Color.WHITE, or whatever it was beforehand, after drawing each actor? \$\endgroup\$ – StrongJoshua Apr 19 '15 at 2:40
4
\$\begingroup\$

The most likely problem is that in one of your actor's draw calls you are forgetting to reset the batch's color. This would cause alpha transparency to carry throughout your entire stage.

Make sure you always reset the batch's color at the end of a draw call where you manipulate it. Here is an example:

public void draw (Batch batch, float parentAlpha) {
    batch.setColor(this.getColor());
    // always make sure to only multiply by the parent alpha
    batch.getColor().a *= parentAlpha;

    // do your drawing

    batch.setColor(Color.WHITE); // reset the color
}
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Same issue. It seems to be due to when the batch is flushed? Anyways basically every Actor sibling seems to also fade with it. Also will happen with any setColor as you might expect. Workaround I have done is just wrap it with a group.

Update: Actually last item in group seems to always have issue, even if wrapped. Need a flush? Or whatever resets the alpha, etc.

Update: StrongJoshua answered it. Due to having actor outside the group and needing to reset the batch color before using it.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Please read my comment on the OP's question. I don't know if that has anything to do with it, but without more code it is the best guess I can give right now. \$\endgroup\$ – StrongJoshua Apr 19 '15 at 2:41
  • \$\begingroup\$ Thanks @StrongJoshua for the reply. I think you maybe confusing what other code would exist due to when you use the framework without a stage. When using a Stage with Actors and Actions you can just do an addAction() like you see above and it will get interpolated for you (i.e. handles batch, draw, etc). Here is a good tutorial if you haven't used a stage yet: github.com/libgdx/libgdx/wiki/Scene2d \$\endgroup\$ – nibuen Apr 19 '15 at 2:45
  • 1
    \$\begingroup\$ I already know how Stage's work (I use them in every project). Why would you use Actors (tables, groups, etc.) if you aren't using a Stage? They are made for that purpose and it makes no sense to use them without one. \$\endgroup\$ – StrongJoshua Apr 19 '15 at 3:15
  • \$\begingroup\$ Sorry I guess just confused your comment. If you set the color of an Actor you don't have reset the color for Actor siblings usually. Though I have seen side affects before and had to reset kind of like you are saying. Though there is no chance to do this in a table since the relationship would be something like: table->cell->actorA->cell->actorB and for some reason if you keep reference to actorA and setColor it will affect actorB. Thus you would have to subclass table to fix. \$\endgroup\$ – nibuen Apr 19 '15 at 3:22
  • \$\begingroup\$ Ack! Sorry @StrongJoshua it was an actor i had living outside a group that needed a reset of the batch color. Thanks alot! I recommend you put your's as answer. \$\endgroup\$ – nibuen Apr 19 '15 at 3:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.