libgdx中的"Game"、"Screen"和"ApplicationAdapter"有什么区别?
What is the difference between "Game", "Screen" and "ApplicationAdapter" in libgdx?
在教程中,有时人们使用 "extends Game",有时使用 "implements Screen",而我已自动生成 "extends ApplicationAdapter"。它们有什么区别?
ApplicationAdapter
允许您创建一个侦听器,但不会强制执行每个方法。如果您熟悉 Swing,请查看 KeyAdapter
,这是相同的想法。
ApplicationListener
允许您处理应用程序事件。这允许您在应用程序生命周期内的某些事件(例如销毁)期间执行代码。
An ApplicationListener is called when the Application is created, resumed, rendering, paused or destroyed. All methods are called in a thread that has the OpenGL context current. You can thus safely create and manipulate graphics resources.
一个Game
是一个支持多屏的ApplicationListener
。您可以使用 setScreen
.
创建多个屏幕并在 em 之间切换
An ApplicationListener that delegates to a Screen. This allows an application to easily have multiple screens.
A Screen
正是它听起来的样子;这就是在给定时间显示的内容。也许是主菜单,也许是真正的游戏。
Represents one of many application screens, such as a main menu, a settings menu, the game screen and so on.
建议您使用 Game
class 作为您游戏的基础,然后创建多个 Screen
实例来表示您可能拥有的不同游戏状态。
在教程中,有时人们使用 "extends Game",有时使用 "implements Screen",而我已自动生成 "extends ApplicationAdapter"。它们有什么区别?
ApplicationAdapter
允许您创建一个侦听器,但不会强制执行每个方法。如果您熟悉 Swing,请查看 KeyAdapter
,这是相同的想法。
ApplicationListener
允许您处理应用程序事件。这允许您在应用程序生命周期内的某些事件(例如销毁)期间执行代码。
An ApplicationListener is called when the Application is created, resumed, rendering, paused or destroyed. All methods are called in a thread that has the OpenGL context current. You can thus safely create and manipulate graphics resources.
一个Game
是一个支持多屏的ApplicationListener
。您可以使用 setScreen
.
An ApplicationListener that delegates to a Screen. This allows an application to easily have multiple screens.
A Screen
正是它听起来的样子;这就是在给定时间显示的内容。也许是主菜单,也许是真正的游戏。
Represents one of many application screens, such as a main menu, a settings menu, the game screen and so on.
建议您使用 Game
class 作为您游戏的基础,然后创建多个 Screen
实例来表示您可能拥有的不同游戏状态。