Libgdx如何停止循环,直到演员动作完成/完成

时间:2015-03-02 14:17:17

标签: java libgdx wait

我将actor添加到名为cells的组中,并且在for循环中,我将操作添加到组内的一组特定单元格中。

我希望这样,循环的下一次迭代不会开始,直到单元格的动作完成。

for (int i = 0; i < cells.length; ++i) {

     cell.addAction(fadeIn(1f));
     // I need to wait here until the action has completed!
}

我可以使用阻止操作或libgdx中的某些操作吗?或者我应该采取特定的方式吗?

显然我需要libgdx继续在后台运行,否则动作根本无法完成,我真的不知道怎么做。

我不能使用RunnableAction,因为它是在执行后调用代码,我只是想停止循环迭代。

谢谢,

1 个答案:

答案 0 :(得分:3)

您可以尝试为fadeIn开始运行所需的计算时间设置每个操作的延迟,而不是阻止循环。

这样的事情:

float delay = 0;
for (int i = 0; i < cells.length; ++i) {
    SequenceAction sa = Actions.sequence(Actions.delay(delay), 
                          Actions.fadeIn(1f));
    cell.addAction(sa);
    delay += 1f; //Increase the delay for the duration of each fadeIn
}

没试过这个。

相关问题