暂停并继续在Libgdx中对演员进行动作 [英] Pause and continue playing an action on actor in Libgdx

查看:92
本文介绍了暂停并继续在Libgdx中对演员进行动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试Libgdx. 这就是我想要实现的,

I am trying out Libgdx. This is what I am trying to achieve,

在演员执行动作时,在演员上定义动作,单击按钮,我们应该能够从同一位置开始和停止动作.

Define an action on an Actor, while the actor is performing the action, on button click we should be able to start and stop the action, from the same position.

我尝试了 stackoverflow答案,但是在再次启动动作之后,actor的动作比以前更快,因为最初我们设置了动作完成的持续时间,并且由于剩下的时间更少,所以运行速度更快.

I tried this stackoverflow answer but after starting the action again, the actor moves faster then before, because initially we had set duration for the action to be finished, and since less time is left, it runs faster.

可以帮忙吗?我错过了什么吗?

Can you please help? am I missing anything?

推荐答案

尝试直接从Actor#actions数组单击时从actor中删除动作,然后再次单击将其重新添加.示例:

Try removing the action from the actor on click directly from Actor#actions array, and then add it back on another click. Example:

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

    }
});

这篇关于暂停并继续在Libgdx中对演员进行动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆