Difference between libgdx Stage and Screen

断了今生、忘了曾经 提交于 2019-12-06 18:43:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/16347297/difference-between-libgdx-stage-and-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!