4

I am trying to fade an Actor out using the Action FadeOut. However, I've discovered that the no actions work at all for my objects. The hierarchy of my classes are like this:

Actor -> MoveableObject -> Knight

Stage -> KnightGroup (Group) -> Knight

Actions for my Knight actors do not work at all. However, actions for my KnightGroup group works. Here is the code for my Knight:

public class Knight extends Players {
public Knight() {
    setWidth(96);
    setHeight(96);
    setPosition(100, 90);

    //Doesn't work
    AlphaAction action = new AlphaAction();
    action.setAlpha(0f);
    action.setDuration(1f);
    addAction(action);

    //Doesn't work
    addAction(fadeOut(1f));
    addAction(Actions.scaleBy(1f, 1f));
}

@Override
public void act(float delta){
    super.act(delta);
}


@Override
public void draw(Batch batch, float parentAlpha) {
    batch.setColor(getColor().r, getColor().g, getColor().b, getColor().a);
    batch.draw(animation[currentState], getX(), getY(), getWidth(), getHeight());
}
}

I can't for the life of me figure out what the problem is. Actions in MoveableObject (the parent of Knight) doesn't work either. My best guess is that wrapping actors in a Group will render the actions of those actors invalid. The KnightGroup is a pretty crucial part of my code though and I would have to do a lot of refactoring to take it out. Can someone else shed some light on this issue?

Daahrien
  • 10,190
  • 6
  • 39
  • 71
Kenneth Wang
  • 191
  • 10
  • Do you call stage.act(delta)? Does a moveBy/moveTo Action work? – Robert P Feb 26 '14 at 07:22
  • Yes, stage.act(delta) is called. Everything works except for actions. moveTo actions don't work either. – Kenneth Wang Feb 26 '14 at 07:42
  • 2
    In your Players class in act(delta) do you call super.act(delta)? Does that act(delta) go back to Actor.act(float delta), because the Action.act(delta) is called inside Actor.act(delta) – Robert P Feb 26 '14 at 07:54
  • That was it! I was missing a super.act() at the top most level of my class hierarchy. After I added it, things worked as expected. Thank you SO much, man! – Kenneth Wang Feb 26 '14 at 18:02
  • I added it as an answer so you can mark it as solved. – Robert P Feb 27 '14 at 07:01

1 Answers1

6

In the Actor class the method act(float delta) calls act(delta) for all registered Actions of this Actor. So you have to make sure, that you call super.act(delta) in every subclass of Actor, so that the act(delta) method in Actor gets called.

Robert P
  • 9,398
  • 10
  • 58
  • 100