1

I have a world that is the GameScreen (20ish objects) which lays all objects as intended. However, when I get GameOver I want to be a blank canvas with just the background and some new objects(a couple objects), but all the existing objects from GameScreen carry over and I cant figure out how to stop it or delete them on the GameOver screen

public class GameScreen extends World
{
    public GameScreen()
    {
      super(600, 400, 1); 
      prepare();
    }

    private void prepare()
    {
      addObjects.......
    }
}


public class GameLost extends GameScreen
{  
    public GameLost()
    {
      removeObjects(GameScreen);
      prepare();
    }

    private void prepare()
    {
      addObjects...
     }
Ryan W
  • 39
  • 6

1 Answers1

0

I'm pretty sure you don't want GameLost extends GameScreen.

Do

class GameLost {
   private Background bg;
   public void paint() {
       paint(bg);
   }
}
class GameScreen {
   private Background bg;
   private List<GameObjects>...
   public void paint() {
       paint(bg);
       gameObjects.forEach(go -> paint(go));
   }
}

which makes it easy to move over the background from game screen to game over screen, without the game objects.

daniu
  • 14,137
  • 4
  • 32
  • 53