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.
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.
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
Screen objects will receive the standard Libgdx lifecycle events as callbacks (
There are no concrete relationships between
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.