title: LibGDX How to put the game in the table? *** FIXED ***
body: <p>I have a game screen in which I want to implement both the game itself and the control buttons. I divided this screen into two parts using TABLE.
  The control buttons and the game are implemented in different classes. Everything works correctly, except for displaying the game.</p>
  
  <p><a href="https://i.stack.imgur.com/nvyGC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nvyGC.png" alt="pic"></a></p>
  
  <p><strong>How to make the game fit in the top window?</strong></p>
  
  <p>Game Screen code</p>
  
  <pre><code>public class GameScreen implements Screen {
      private Main parent;
      private Stage stage;
      public static SnakeControl snakeControl;
      private SpriteBatch batch;
      private GameControl game;
  
      public GameScreen(Main main) {
          parent = main;
  
          stage = new Stage(new ScreenViewport());
          Gdx.input.setInputProcessor(stage);
          snakeControl = new SnakeControl();
  
          GameAssets.instance().loadAssets();
          batch = new SpriteBatch();
          game = new GameControl();
      }
  
      @Override
      public void show() {
          Table table = new Table();
          table.setFillParent(true);
          table.setDebug(true);
  
          table.row();
          table.add(game).expand().pad(10f, 5f, 10f, 5f);
          table.row();
          table.add(snakeControl.get_tSnakeControl()).fillX().height(GameInfo.SCREEN_HEIGHT/3.5f).pad(0f, 5f, 10f, 5f);
  
          stage.addActor(table);
      }
  
      @Override
      public void render(float delta) {
          game.update(Gdx.graphics.getDeltaTime());
          clearScreen();
          batch.begin();
          game.render(batch);
          stage.act(Gdx.graphics.getDeltaTime());
          stage.draw();
          batch.end();
      }
  
      private void clearScreen() {
          Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
          Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      }
  
      @Override
      public void resize(int width, int height) {
          stage.getViewport().update(width, height, true);
      }
  
      @Override
      public void pause() {
  
      }
  
      @Override
      public void resume() {
  
      }
  
      @Override
      public void hide() {
  
      }
  
      @Override
      public void dispose() {
          stage.dispose();
          batch.dispose();
          GameAssets.instance().dispose();
      }
  </code></pre>
  
  <p>The Game code</p>
  
  <pre><code>public class GameControl extends Actor {
  
      private Board board;
      private Snake snake;
      private float timeState;
      private BitmapFont font;
  
      private GameObject food;
      private boolean isGameOver;
  
      public GameControl() {
          TextureAtlas atlas = GameAssets.instance().get(GameAssets.SNAKE_PACK);
          font = GameAssets.instance().get(GameAssets.PIXEL_FONT);
          snake = new Snake(atlas);
          board = new Board(snake, GameInfo.SCREEN_WIDTH, GameInfo.SCREEN_HEIGHT);
          food = board.generateFood();
          init();
      }
  
      private void init() {
          GameSoundsPlayer.init();
          GameSoundsPlayer.playMusic(GameAssets.MEMO_SOUND, false);
      }
  
      public void update(float delta) {
          if (snake.hasLive()) {
              timeState += delta;
              snake.handleEvents();
              if (timeState &gt;= .09f) {
                  snake.moveBody();
                  timeState = 0;
              }
              if (snake.isCrash()) {
                  snake.reset();
                  snake.popLife();
                  GameSoundsPlayer.playSound(GameAssets.CRASH_SOUND, false);
              }
              if (snake.isFoodTouch(food)) {
                  GameSoundsPlayer.playSound(GameAssets.EAT_FOOD_SOUND, false);
                  Scorer.score();
                  snake.grow();
                  food = board.generateFood();
              }
          } else {
              gameOver();
              if (Gdx.input.isKeyJustPressed(Input.Keys.ANY_KEY)) start();
          }
      }
  
      private void gameOver() {
          isGameOver = true;
          GameSoundsPlayer.stopMusic(GameAssets.MEMO_SOUND);
          GameSoundsPlayer.playMusic(GameAssets.GAME_OVER_SOUND, false);
      }
  
      private void start() {
          GameSoundsPlayer.playMusic(GameAssets.MEMO_SOUND, false);
          GameSoundsPlayer.stopMusic(GameAssets.GAME_OVER_SOUND);
  
          isGameOver = false;
          snake.reset();
          snake.restoreHealth();
          food = board.generateFood();
          Scorer.reset();
      }
  
      public void render(SpriteBatch batch) {
          board.render(batch);
          food.draw(batch);
          snake.render(batch);
  
          if (isGameOver) {
              font.draw(batch, "GAME OVER", (GameInfo.SCREEN_WIDTH - 100) / 2, (GameInfo.SCREEN_HEIGHT + 100) / 2);
              font.draw(batch, "Press any key to continue", (GameInfo.SCREEN_WIDTH - 250) / 2, (GameInfo.SCREEN_HEIGHT + 50) / 2);
          }
  
          font.draw(batch, "Player: ", GameInfo.SCALE * 4, GameInfo.SCREEN_HEIGHT - 10);
          font.draw(batch, "Score: " + Scorer.getScore(), GameInfo.SCALE / 2, GameInfo.SCREEN_HEIGHT - 10);
          font.draw(batch, "Size: " + snake.getBody().size(), GameInfo.SCALE / 2, GameInfo.SCREEN_HEIGHT - 40);
      }
  }
  </code></pre>