Ok so basically I'm trying to decorate a Libgdx Actor class with other actions
public Shake(Button buttonToBeDecorated) extends ButtonDecorator {
super(buttonToBeDecorated);
Array<Action> actions = buttonToBeDecorated.getActions();
for (Action action : actions)
addAction(action);
addAction(Actions.forever(new SequenceAction(
Actions.moveBy(10, 0, 0.5f),
Actions.moveBy(-10, 0, 0.5f)))
);
}
however actions from toBeDecorated class (which are also wrapped in SequenceAction) doesn't apply to instance of Shake. I'm sure that actions are passed properly because I am able to print them out. But I'm not getting combined effect, maybe some of you would know why ? Thanks
EDIT: (based on new response from @DHa)
I believe I have understood this Group-Workaround that you presented. However I still can't manage to make it work. For this instance let's assume that we decorate button object with Shake action and then with FadeOut action (Both of these classes have "Group" variable extended from parent class ButtonDecorator). So creating this type of object would look like this:
Button button = new Decorators.FadeOut(new Decorators.Shake(new Buttons.PlayButton()));
And classes:
//Shake class - we just simply add Shake actor to group and then add a specific action
//this works perfectly fine by itself - new Decorators.Shake(new Buttons.PlayButton())
public static class Shake extends ButtonDecorator {
public Shake(Button buttonToBeDecorated) {
super(buttonToBeDecorated);
group.addActor(this);
group.addAction(Actions.forever(new SequenceAction(
Actions.moveBy(10, 0, 0.5f),
Actions.moveBy(-10, 0, 0.5f))));
}
}
//In FadeOut we are trying to decorate Shake object with another Action
public static class FadeOut extends ButtonDecorator {
public FadeOut(Button buttonToBeDecorated) {
super(buttonToBeDecorated);
Array<Action> actions = buttonToBeDecorated.group.getActions(); //getting actions from Shake
group.addActor(buttonToBeDecorated);
/* I'm guessing that the whole workaround is in this line. We are adding
Shake-actor to FadeOut group so Shake-actions should no longer apply
to Shake-object and can be applied to our new FadeOut button */
group.addActor(this); //Adding FadeOut to it's own group
for (Action action : actions)
group.addAction(Actions.parallel(action,new SequenceAction(Actions.fadeOut(3), Actions.fadeIn(3))))
//besides adding shake actions to FadeOut object we are also adding parallel fadeout action
}
}
I don't know why but still only one action (fading out) is applied to created object