暂停并继续对 Libgdx 中的演员播放动作

Pause and continue playing an action on actor in Libgdx

我正在尝试 Libgdx。 这就是我想要实现的目标,

在 Actor 上定义一个动作,当 actor 执行动作时,单击按钮我们应该能够从相同位置开始和停止动作。

我试过这个Whosebug answer但是再次开始动作后,actor的移动速度比之前快了,因为一开始我们设置了动作完成的时长,剩下的时间少了,所以跑得更快.

你能帮忙吗?我错过了什么吗?

尝试直接从 Actor#actions 数组中删除演员点击时的动作,然后在再次点击时将其添加回去。示例:

final Actor actor = // ... initialize your actor;
final Action action = Actions.forever(Actions.rotateBy(360f, 3f, Interpolation.bounceOut));
actor.addAction(action);

actor.addListener(new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y) {
        Array<Action> actions = actor.getActions();
        if (actions.contains(action, true)) {
            // removing an action with Actor#removeAction(Action) method will reset the action,
            // we don't want that, so we delete it directly from the actions array
            actions.removeValue(action, true);
        } else {
            actor.addAction(action);
        }

    }
});