I cannot figure out, how to temporary disable the DragListener
while there is an ongoing Action
on the Actor
. When I touch the Actor
while there is an ongoing Action
it gets interrupted and the new Action
is executed, which leads to a "drift" of the Actor
. e.g. I shake the Actor
, but when it is interrupted, the following Action
is based on the interrupted position of the Actor
.
Adding Actions inside touchUp
method:
RotateByAction rotL = new RotateByAction();
rotL.setAmount(-3);
rotL.setDuration(0.05f);
RotateByAction rotR = new RotateByAction();
rotR.setAmount(6);
rotR.setDuration(0.05f);
RotateByAction rotBack = new RotateByAction();
rotBack.setAmount(-3);
rotBack.setDuration(0.05f);
SequenceAction seq = new SequenceAction();
seq.addAction(rotL);
seq.addAction(rotR);
seq.addAction(rotBack);
temp.setOrigin(temp.getWidth()/2,temp.getHeight()/2);
temp.addAction(seq);
I tried to do something like this inside the Render method of the Actor
:
if (this.getActions().size > 0){//or hasActions()
this.setTouchable(Touchable.disabled);
}
else{
this.setTouchable(Touchable.enabled);
}
But that leaves the Actor
untouchable!
What you should do instead is use Actions.touchable
to disable touch at the start of your action and then enable it again at the end. You can also string multiple actions together, using sequence
or parallel
.
temp.addAction(Actions.sequence(
Actions.touchable(Touchable.disabled),
rotL,
rotR,
rotBack,
Actions.touchable(Touchable.enabled)
));