在Libgdx中重复序列操作

问题描述 投票:0回答:1

我有一个名为箭头的演员,我想重复一个序列动作。

此箭头指向一个演员,如果单击该箭头,箭头应该淡出。

这是我的代码:

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个回答
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));
    }
});

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

arrow.addAction(Actions.sequence(
        Actions.fadeOut(1f), Actions.run(new Runnable() {
            @Override
            public void run() {
                arrow.remove();
            }
        }))
);
© www.soinside.com 2019 - 2024. All rights reserved.