【问题标题】:Repeat a Sequence Action in Libgdx在 Libgdx 中重复序列操作
【发布时间】:2017-12-25 13:19:59
【问题描述】:

我有一个叫箭头的演员,我想对它重复一个序列动作。

这个箭头指向一个演员,如果被点击,这个箭头应该淡出。

这是我的代码:

Action moving = Actions.sequence(
                (Actions.moveTo(arrow.getX(), arrow.getY() - 35, 1)),
                (Actions.moveTo(arrow.getX(), arrow.getY(), 1)));
arrow.addAction(moving);
actor.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                arrow.addAction(Actions.fadeOut(1));
            }
        });

代码工作正常,但我想重复“移动”动作,直到演员被点击。

我在这个问题Cannot loop an action. libGDX 中阅读了有关 RepeatAction 的信息,但我不知道如何申请

【问题讨论】:

    标签: libgdx scene2d


    【解决方案1】:

    在这种情况下,您可以使用 RepeatAction,Actions.forever()

    final Action moving = Actions.forever(Actions.sequence(
            (Actions.moveTo(arrow.getX(), arrow.getY() - 35, 1)),
            (Actions.moveTo(arrow.getX(), arrow.getY(), 1))));
    arrow.addAction(moving);
    actor.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            // you can remove moving action here
            arrow.removeAction(moving);
            arrow.addAction(Actions.fadeOut(1f));
        }
    });
    

    如果要在淡出后从Stage 中删除arrow,可以使用RunnableAction

    arrow.addAction(Actions.sequence(
            Actions.fadeOut(1f), Actions.run(new Runnable() {
                @Override
                public void run() {
                    arrow.remove();
                }
            }))
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-28
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 2021-06-28
      • 2019-09-04
      • 1970-01-01
      相关资源
      最近更新 更多