3

I want an animated splash screen like fade in fade out for which I am doing in resize method as follows

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);
  }
}
Nishant Anindya
  • 539
  • 5
  • 21

2 Answers2

3

Try changing your new Action() to new RunnableAction(){ public void run(){.....

Herer are more actions also some other explanation how they work. refare to an other question.
->Actions
Also take a look at:
screen2D, libgdx wiki about actions

Community
  • 1
  • 1
bemeyer
  • 6,154
  • 4
  • 36
  • 86
  • Does any body tells that how can apply more animations except fade in fade out in libgdx.. Because whatever I tried was not up to the mark...:( – Nishant Anindya Apr 13 '13 at 13:09
  • Added a link for you. I'd suggest while it fadeIn a movement from down to the Center of the screen for example. – bemeyer Apr 13 '13 at 13:46
2

Declare this variable

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));
    }
};
Nishant Anindya
  • 539
  • 5
  • 21