# libgdx actors and instant actions

I'm having trouble with actors and actions. I have a list of actors, they all have either no action, or 1 sequence action

This sequence action has either :

• a couple of actions (some are instant, some have duration > 0)
• a couple of actions followed by a parallel action.

My problem is the following:

some of the instant actions are used to set the position and the alpha of the actor. So when one of the action is "move to x,y and set alpha to 0" the actor is visible for one frame at position 0,0 , move instantly to x,y for the next frame, and then disappears.

Though this behaviours is to be expected, I want to avoid it. How can I achieve that?

I tried to intercept the actions before I put actors in the stage but I need the stage width/height for some actions. So something like :

Action actionSequence = actor.getActions().get(0);
Array<Action> actions = ((SequenceAction) actionSequence).getActions();
for(Action act : actions){
if(act.act(0))
System.out.println("action " + act.toString() + " successfully run");
else
System.out.println("action " + act.toString() + " wasn't instant");
}


won't work.

It gets even more complicated when an actor can also have a repeat action in stead of the sequence action (because you have to only run the actions that have duration 0 once without repeat, and then start the repeat).

Any help is appreciated.

• Why don't you set the alpha to 0 and then queue up another action that does the displacement? Sep 12 '13 at 2:46
• I tried but that was a hassle and didn't work very well. Mostly because it interfered with other alpha actions during repeat. But I found another way around. Sep 12 '13 at 17:31

Okay I found a way around.

I built a custom actor class that extends Image and overwrote CustomActor's draw() method like that

@Override
public void draw(SpriteBatch batch, float parentAlpha) {
if(frameCount < 4){
frameCount++;
return;
}
super.draw(batch, parentAlpha);
}


Basically, the first 3 frames aren't drawn. During those frames the actor is being placed correctly by the first instantaneous actions and doesn't glitch through the screen.

Kinda hackey but that will do it for now.

It looks like you are trying to put these actions in a SequenceAction, put both move and alpha action into a ParallelAction which then put into your sequence.

actor.addAction(Actions.sequence(Actions.parallel(moveAction,alphaAction), moreActionsInSequence));


Also consider using VisibleAction (Actions.show/hide/visible) instead of alpha 0 for hiding Actors.

I had this Problem a while ago. It's because of your Stage transparancy. Before you init your actions you need to set it to zero . Im currently at my phone so I don't know if that's right :

Stage.getRoot().getColor.a = 0;