TheMoonrise
TheMoonrise

Reputation: 35

LibGDX Scene2d Action affects multiple Actors

I am working on my second app and it went quite well so far. But now I got stuch on a problem I just can´t manage to find a solution for.

I´ve been using scene2d stage to display everything. Now I´ve added a black image which fades out whenever a new Screen is called(as a transition).

My problem is, that when I add the fade out action to my black Image it also fades out the background. Interestingly only the background is affected, no other Actor what so ever.

I´ve tried changing the order of the Actors, putting them into groups, clearing all actions from the background, setting his alpha to 1 but nothing worked.

Thanks for helping me !

For the background:

public class BackgroundColor extends Actor {

public BackgroundColor(int x) {

    this.setBounds(x, 0, 270, 960);
}

public void act(float delta) {

}

public void draw(Batch batch, float alpha) {

        batch.draw(image, this.getX(), this.getY(), this.getWidth(), this.getHeight());


    }
}

For the screen:

public class GameScreen implements Screen {

public Stage stage;

public BackgroundColor backgroundColor;

public Image black;

public GameScreen() {

    stage = new Stage(new ExtendViewport(540, 900, 540, 960));

    Gdx.input.setInputProcessor(stage);
    setupStage();
}

private void setupStage() {

    backgroundColor = new BackgroundColor(0);
    stage.addActor(backgroundColor);

    //this is the black layer
    black = new Image(AssetLoader.black);
    black.setBounds(0, 0, stage.getWidth(), stage.getHeight());
    stage.addActor(black);
    black.addAction(Actions.sequence(Actions.fadeOut((float)0.5), Actions.touchable(null)));
}

@Override
public void show() {

}

@Override
public void render(float deltaTime) {

    Gdx.gl.glClear(0);
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
}

Upvotes: 2

Views: 637

Answers (1)

TheMoonrise
TheMoonrise

Reputation: 35

So, I kinda figured it out...

apparently having a different Image as the first layer of the stage solves the issue.

I added in a random Image before the backgroundColor = new BackgroundColor(0); and that fixed it.

I still have no Idea what causes this, maybe I missed something...

Would be great if you could tell me what is going on here!

Cheers

Upvotes: 1

Related Questions