3

我想要一个像淡入淡出这样的动画启动画面,我正在调整大小方法中,如下所示

public class SplashScreen extends GamePlayScreen {

@Override
public void resize(int width, int height) {
    super.resize(width, height);
    stage.clear();
    Drawable splashDrawable = new TextureRegionDrawable(region);
    splashImage = new Image(splashDrawable, Scaling.stretch);
    splashImage.setFillParent(true);
    splashImage.getColor().a = 0f;
    splashImage.addAction(Actions.sequence(Actions.fadeIn(0.75f),
            Actions.delay(1.75f), Actions.fadeOut(0.75f), 
            new Action() {
                @Override
                public boolean act(float delta) {
                    // the last action will move to the next screen
                    System.out.println("moving to next screen");
                    splashGameObj.setScreen(new GamePlayScreen(
                            splashGameObj));
                    return true;
                }
            }));
    stage.addActor(splashImage);
  }
}
4

2 回答 2

3

尝试将您的更改new Action()new RunnableAction(){ public void run(){.....

这里有更多的动作,还有一些其他的解释它们是如何工作的。转至另一个问题。
->Actions
也看看:
screen2D, libgdx wiki about actions

于 2013-04-13T11:33:16.180 回答
2

声明这个变量

private Stage stage;    

@Override
public void render(float delta) {
    // TODO Auto-generated method stub
    update();
    draw(delta);
}

private void draw(float delta) {
    // TODO Auto-generated method stub
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    stage.act(delta);
    stage.draw()
}

@Override
public void resize(int width, int height) {
    stage.setViewport( width, height, true );

}

@Override
public void show() {
    // TODO Auto-generated method stub
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);

    Image splashImage = new Image(region);
    splashImage.addAction( Actions.sequence( Actions.fadeOut( 0.0001f ), Actions.fadeIn( 5f ),
            Actions.run(onSplashFinishedRunnable) ) );



    stage.addActor(splashImage);
}

Runnable onSplashFinishedRunnable = new Runnable() {

    @Override
    public void run() {
        // TODO Auto-generated method stub
        splashGameObj.setScreen(new GamePlayScreen(splashGameObj));
    }
};
于 2013-04-13T12:33:47.450 回答