3
\$\begingroup\$

I am looking for someone to point me in the right direction. I am working in libgdx. I have a game where a player will approach an object on a map and then interact with it. On interaction a new screen should come up, that then has separate interaction.

Think, lockpicking. if you walk to a door, a minigame would popup with the lock on the screen. All background art and action halts while this happens.

I was considering using an Object that triggers a Looped event that you can't escape until the condition is met EG: while(!Finished){lockpick()} then creating a render() inside lockpick()... is this a terrible idea? Should I just dump out to a different screen, and reload my game screen from saved settings? I really don't know the best way to handle this...

\$\endgroup\$
2
  • \$\begingroup\$ You can easily have your Game object at the top level call setScreen(lockpickingScreen), and then when done call setScreen(gameplayScreen) without having to save and load any data. Just keep the screens as variables in the Game class. \$\endgroup\$
    – bazola
    Commented Aug 17, 2015 at 18:20
  • \$\begingroup\$ @bazola but he wants his game world visible at background. You can extend the game class to have more than one scene. \$\endgroup\$
    – Arda Kara
    Commented Aug 18, 2015 at 10:21

1 Answer 1

0
\$\begingroup\$

I would do it with Scene2d. You can have your game with a normal game loop and a SpriteBatch to manually update and draw the game and additionally you can have a Scene2d Stage that you can use to display whatever UI components you wish above your game (or below, depends on the order of calling the draw methods). It's a very nice library, great I would say, and it's relatively easy to pick up and start doing stuff. Also there are a lot of books and articles about it. Simplified it looks like this in code.

class MyGame extends Game {
   public SpriteBatch batch;
   public Stage stage;

   public void create() {
      batch = new SpriteBatch(.....); // construct depending on your needs
      stage = new Stage(.....); // construct depending on your needs
   }

   public void render() {
      myGame.update(delta);
      stage.act(delta);

      batch.begin();
      renderTheGame(batch);
      batch.end();

      stage.draw();
   }
}

The described situation is not blocking for your game - Stage does not block anything - both your game and your UI by the Stage are updated and drawn every frame. But if you want to block in case of a UI Dialog popping-up by the Stage, you can easily make an empty Game State (where the update,render method just don't do anything) and you can be in that state until the user closes the Dialog.

The benefits of using Scene2d is that it's super fast, relatively easy and it gives you a lot of things like animate the UI, skinning, 9patches, group transformations. Even if you want to write this functionality by yourself, I would recommend to look at the source of the Scene2D framework/classes, as they are very clean and well-written pieces of code.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .