-1

I have the following classes

1- Level Class which has

Stage stage;
MyActor[] myActors;
boolean isCompleted = false; 


public void checkSolution() {
        if(myActor[0].getRotation() > 180) {
            isCompleted = true;
        }
    }

public void render(float delta) {
        stage.act(delta);
        stage.draw();
        checkSolution();
    }

2- Data Class which holds an ArrayList<Level> levels

3- GameScreen Class which has these methods

@Override
    public void show() {
        data = new Data();
        data.loadLevels();
        level = data.levels.get(0);
        Gdx.input.setInputProcessor(level.stage);
    }

    @Override
    public void render(float delta) {
        level.render(delta);
    }

How to move to the next level and remove the previous one from memory ?

Where should I call stage.dispose() of the previous level ?

MAGS94
  • 500
  • 4
  • 15

1 Answers1

1

One of possible solution is to start a new GameScreen with the next level. It's not quite clear what pattern you use in your code. So, suppose that your GameScreen class has a public constructor

public GameScreen(Game game, int level) {
        this.game = game;
        this.level = level;
    }

then, it depends on how you load your levels, I may assume, that you use button with the number of level on it. So, you can pass that number to constructor and load all necessary assets:

data.loadLevels();
level = data.levels.get(level);

So, and final step is your checkSolution method where your should add:

if(isCompleted) {
    game.setScreen(new GameScreen(game, level + 1));
}

Hope, you got the idea.

Enigo
  • 3,685
  • 5
  • 29
  • 54