android – Difference between libgdx Stage and Screen-ThrowExceptions

Exception or error:

I’m making a game, and I see in tutorials some people using Stage class, and others using the Screen class, but I can’t figure out the diference.

How to solve:

A Stage holds Actor instances and updates/animates them and manages hit-detection among them. Its the root of the scene2d “scene graph” API. The Stage is one way of managing the list of objects to draw, their state on the screen (textures, animation state, size, etc), and their interactions with the user. The provided Stage code in Libgdx is mostly oriented towards UI elements like buttons and lists, but the core is flexible enough to contain game elements too.

A Screen generally represents one full-screen UI “page”. For example, you might have a “Main Menu” screen, an “Options” screen, a “main game” screen and an “end credits” screen. The Screen instances are generally managed by a Game instance. When used with a Game the Screen objects will receive the standard Libgdx lifecycle events as callbacks (pause, resume, resize, render, etc).

There are no concrete relationships between Stage and Screen in Libgdx. But its easiest to think of an example where the “main menu” screen is implemented by a Stage that manages the buttons in the main menu. When the user hits one of the buttons, the game might switch to the main game-play screen, and release some of the resources held by the main menu. The game-play screen might use a Stage or might use raw OpenGL to implement the game.

Leave a Reply

Your email address will not be published. Required fields are marked *