LibGdx - 屏幕之间的转换

时间:2012-07-06 12:06:24

标签: screen libgdx

我正在尝试更改Libgdx屏幕之间的动画。我想写自定义动画(淡入淡出,淡出等)。有人能给我一个线索吗? 我似乎无法在Libgdx代码中找到转换的实现。

4 个答案:

答案 0 :(得分:12)

这就是我的所作所为:

FadeIn非常简单,只需将其添加到你的fadein Screens show():

stage.getRoot().getColor().a = 0;
stage.getRoot().addAction(fadeIn(0.5f));

FadeOut有点棘手。您不想立即切换屏幕,因此不要调用game.setScreen(newScreen)在您的淡出屏幕中创建一个方法,如下所示:

public void switchScreen(final Game game, final Screen newScreen){
    stage.getRoot().getColor().a = 1;
    SequenceAction sequenceAction = new SequenceAction();
    sequenceAction.addAction(fadeOut(0.5f));
    sequenceAction.addAction(run(new Runnable() {
        @Override
        public void run() {
            game.setScreen(newScreen);
        }
    }));
    stage.getRoot().addAction(sequenceAction);
}

像这样,你会在淡出过程中延迟屏幕切换。

答案 1 :(得分:5)

我使用Scene2D和通用补间引擎实现了一些滑动过渡。你可以在这里找到示例代码。

http://www.netthreads.co.uk/2012/02/09/libgdx-scene2d-demo-with-scene-transitions/

更新:本文说明了我实现滑动过渡的方法。底部有一个链接,可以带您到这里进行一组演示https://github.com/alistairrutherford/libgdx-demos

有关如何构建演示的明确说明,但您至少需要掌握maven以及如何设置它。

答案 2 :(得分:4)

我实施了类似的方法。感谢Gustavo Steigert,我从他的博客中学到了很多东西 在这里你可以找到他的fadeIn和fadeOut序列的例子。

http://steigert.blogspot.in/2012/02/3-libgdx-tutorial-scene2d.html

你可以完整地浏览他的博客,以更好地了解事物的流程,并在帖子的源代码中找到每个帖子的标签。

答案 3 :(得分:0)

这是我的游戏在屏幕之间的过渡动​​画中的示例代码: 在%课程中:

MainGame

我的所有屏幕都延伸为@Override public void setScreen(final Screen screen) { if (getScreen() == null) { createScreenInAction(screen); return; } createScreenOutAction(getScreen(), new Runnable() { @Override public void run() { createScreenInAction(screen); } }); } private void createScreenOutAction(final Screen screen , Runnable runnable) { Actor actor = ((BaseScreenAdapter) screen).getStage().getRoot(); actor.setOrigin(WIDTH_HALF,HEIGHT_HALF); actor.getColor().a = 1; SequenceAction sequenceAction = new SequenceAction(); sequenceAction.addAction(Actions.parallel(Actions.alpha(0,SCREEN_SWITCH_DURATION) , Actions.scaleTo(1.5f,1.5f , SCREEN_SWITCH_DURATION, Interpolation.exp5))); sequenceAction.addAction(Actions.run(runnable)); actor.addAction(sequenceAction); } private void createScreenInAction(final Screen screen) { StarsGame.super.setScreen(screen); Actor actor = ((BaseScreenAdapter) screen).getStage().getRoot(); actor.setOrigin(WIDTH_HALF,HEIGHT_HALF); actor.getColor().a = 0; SequenceAction sequenceAction = new SequenceAction(); sequenceAction.addAction(Actions.scaleTo(1.5f,1.5f , 0)); sequenceAction.addAction(Actions.parallel(Actions.alpha(1,SCREEN_SWITCH_DURATION) , Actions.scaleTo(1.0f,1.0f , SCREEN_SWITCH_DURATION , Interpolation.exp5))); actor.addAction(sequenceAction); }

BaseScreenAdapter