简体   繁体   中英

Libgdx how to stop for loop until actor action has finished/completed

I have actors added to a group called cells, and in a for loop I add actions to a specific set of cells within the group.

I would like it so that the next iteration of the loop is not started until the cell's action has completed.

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

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

Is there a blocking action I can use or something in libgdx? Or is there a specific way I should do this?

Obviously I need libgdx to keep running in the background otherwise the action will not complete at all, I really have no idea on how to do this.

I cannot use RunnableAction as that is for calling code after execution, I simply want to stop the loop iterating.

Thanks,

Instead of blocking the loop, you could try setting a delay on each action for the calculated time it will take for the fadeIn to start running.

Something like this:

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
}

Didn't test this tho.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM