不能在同一 ActionSequence 中 运行 2 运行nable 动作

can't run 2 runnable action in same ActionSequence

我试图在相同的动作序列中 运行 2 Runnable 动作,但我得到一个错误,说它 cannot resolve constructor SuquenceAction.. 不确定我是否错过了一些完全明显的东西,只是有视线不好,但似乎不能 运行 2 Runnable action in sequence。解决方法是什么?如果我在这里遗漏了语法错误,我深表歉意。

错误:

no suitable constructor found for SequenceAction(ColorAction,RunnableAction,ColorAction,ColorAction,ColorAction,RunnableAction,ColorAction)

ColorAction colorToBlack= new ColorAction();
                    colorToBlack.setDuration(0.2f);
                    colorToBlack.setEndColor(Color.BLACK);
                    colorToBlack.setTime(0.2f);

                    ColorAction colorToWhite = new ColorAction();
                    colorToWhite.setDuration(0.2f);
                    colorToWhite.setEndColor(Color.WHITE);
                    colorToWhite.setTime(0.2f);

                    ColorAction wait = new ColorAction();
                    wait.setDuration(2.5f);
                    wait.setTime(2.5f);

                    ColorAction colorToBlack2= new ColorAction();
                    colorToBlack2.setDuration(0.2f);
                    colorToBlack2.setEndColor(Color.BLACK);
                    colorToBlack2.setTime(0.2f);

                    ColorAction colorToWhite2 = new ColorAction();
                    colorToWhite2.setDuration(0.2f);
                    colorToWhite2.setEndColor(Color.WHITE);
                    colorToWhite2.setTime(0.2f);

                SequenceAction sq = new SequenceAction(colorToBlack,Actions.run(new Runnable() {
                    @Override
                    public void run() {

                    }
                }),colorToWhite,wait,colorToBlack2,Actions.run(new Runnable() {
                    @Override
                    public void run() {

                    }
                }),colorToWhite2);

如您在错误消息中所见,未找到构造函数。这是因为SequenceAction class中没有构造函数可以执行7个Actions。最大值为 5。

这是 SequenceAction

的 JavaDoc

解决方案是,创建 SequenceAction 对象并按顺序逐一添加操作。

SequenceAction sq = new SequenceAction();

sq.addAction(colorToBlack);
sq.addAction(Actions.run(() -> {/**Using lambda expression, it's similar to New Runnable() { run() } **/} ));
sq.addAction(colorToWhite);
sq.addAction(wait);
sq.addAction(colorToBlack2);
sq.addAction(Actions.run(() -> {}));
sq.addAction(colorToWhite2);

如果你查看 LibGdx 代码,在构造函数中他们正在做的是

public SequenceAction (Action action1, Action action2, Action action3, Action action4, Action action5) {
        addAction(action1);
        addAction(action2);
        addAction(action3);
        addAction(action4);
        addAction(action5);
}

和我给你的差不多。

希望对您有所帮助:)