简体   繁体   English

libgdx中“Game”,“Screen”和“ApplicationAdapter”有什么区别?

[英]What is the difference between “Game”, “Screen” and “ApplicationAdapter” in libgdx?

In tutorials sometimes people use "extends Game", sometimes "implements Screen" and i have auto-generated "extends ApplicationAdapter". 在教程中,有时人们使用“扩展游戏”,有时“实现屏幕”,我自动生成“扩展ApplicationAdapter”。 What is the difference between them? 他们之间有什么区别?

ApplicationAdapter allows you to create a listener, but not being forced to implement every method. ApplicationAdapter允许您创建一个侦听器,但不强制实现每个方法。 If you're familiar with Swing, check out KeyAdapter , it's the same idea. 如果您熟悉Swing,请查看KeyAdapter ,这是一样的想法。

An ApplicationListener allows you to handle application events. ApplicationListener允许您处理应用程序事件。 This allows you to execute code during certain events within the application life-cycle (such as destroy). 这允许您在应用程序生命周期内的某些事件(例如destroy)中执行代码。

An ApplicationListener is called when the Application is created, resumed, rendering, paused or destroyed. 在创建,恢复,呈现,暂停或销毁应用程序时调用ApplicationListener。 All methods are called in a thread that has the OpenGL context current. 在具有OpenGL上下文当前的线程中调用所有方法。 You can thus safely create and manipulate graphics resources. 因此,您可以安全地创建和操作图形资源。

A Game is an ApplicationListener that supports multiple screens. Game是支持多个屏幕的ApplicationListener You can create multiple screens and switch between em using setScreen . 您可以使用setScreen创建多个屏幕并在em之间切换。

An ApplicationListener that delegates to a Screen. 委托给Screen的ApplicationListener。 This allows an application to easily have multiple screens. 这允许应用程序容易地具有多个屏幕。

A Screen is exactly what it sounds like; Screen正是它听起来的样子; it's what will be displayed at that given time. 它是在给定时间显示的内容。 Maybe it's a main menu, maybe it's the actual game. 也许它是一个主菜单,也许它是真正的游戏。

Represents one of many application screens, such as a main menu, a settings menu, the game screen and so on. 表示许多应用程序屏幕中的一个,例如主菜单,设置菜单,游戏屏幕等。

It's recommended you use the Game class for the base of your game, then create multiple Screen instances of the different possible game states you will have. 建议您使用Game类作为Game的基础,然后创建您将拥有的不同可能游戏状态的多个Screen实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM