不能在同一个ActionSequence中运行2个可运行的动作

时间:2016-01-10 17:20:23

标签: libgdx runnable

我试图在同一个动作序列中运行2个Runnable动作,但是我得到一个错误,说它cannot resolve constructor SuquenceAction ..不确定我是否错过了一些完全明显的东西,只是视力不好,但它出现了那个人不能按顺序运行2个Runnable动作。解决方法是什么?如果我在这里错过了语法错误,我真诚地道歉。

错误:

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);

1 个答案:

答案 0 :(得分:2)

正如您在错误消息中看到的,找不到构造函数。这是因为SequenceAction类中没有构造函数可以执行7个操作。最大值为5.

以下是SequenceAction

的JavaDoc

解决方法是,创建SequenceAction对象并按顺序添加操作1。

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);
}

它与我给你的相似。

我希望它有所帮助:)。