Libgdx provides six core modules that allow you to access the various parts of the system your application will run on. What makes these modules so great for you as a developer is that they provide you with a single Application ProgrammingInterface (API) to achieve the same effect on more than just one platform
every module is accessible as a static field in the Gdx class.
The application module
功能一:调试
选择调试输出内容的详细程度 Gdx.app.setLogLevel(Application.LOG_DEBUG)
• LOG_NONE: This prints no logs. The logging is completely disabled.
• LOG_ERROR: This prints error logs only.
• LOG_INFO: This prints error and info logs.
• LOG_DEBUG: This prints error, info, and debug logs.
输入调试内容
Gdx.app.log("MyDemoTag", "This is an info log.");
Gdx.app.debug("MyDemoTag", "This is a debug log.");
Gdx.app.error("MyDemoTag", "This is an error log.");
功能二:关闭程序窗口,用这条语句十分的有必要,(英文的大概意思是可以防止内存泄露,特别针对手机而言,这样做是绝对的必要的,因为手机的资源相对于电脑来说十分的有限)!
Gdx.app.exit();
You should always do a graceful shutdown when you want to
terminate your application. Otherwise, you will risk creating
memory leaks, which is a really bad thing. On mobile devices,
memory leaks will probably have the biggest negative impact
due to their limited resources.
功能三:保存数据Persisting data
If you want to persist your data, you should use the Preferences class. It is merely
a dictionary or a hash map data type which stores multiple key-value pairs in a
file. Libgdx will create a new preferences file on the fly if it does not exist yet. You
can have several preference files using unique names in order to split up data into
categories. To get access to a preference file, you need to request a Preferences
instance by its filename as follows:
Preferences prefs = Gdx.app.getPreferences("settings.prefs");
To write a (new) value, you have to choose a key under which the value should be
stored. If this key already exists in a preferences file, it will be overwritten. Do not
forget to call flush() afterwards to persist the data, or else all the changes will
be lost.
prefs.putInteger("sound_volume", 100); // volume @ 100%
prefs.flush();
功能四:查询内存使用情况(帮助改进程序的效率,找出可能导致内存冲突的部分)
You can query the system to find out its current memory footprint of your
application. This may help you find excessive memory allocations that could lead to
application crashes. The following functions return the amount of memory (in bytes)
that is in use by the corresponding heap:
long memUsageJavaHeap = Gdx.app.getJavaHeap();
long memUsageNativeHeap = Gdx.app.getNativeHeap();
Graphics module图形模块
The graphics module can be accessed either through Gdx.getGraphics() or by
using the shortcut variable Gdx.graphics.
Querying delta time查询页面刷新时间
Query Libgdx for the time span between the current and the last frame in seconds by
calling Gdx.graphics.getDeltaTime().
Querying display size查询画面大小
Query the device's display size returned in pixels by calling Gdx.graphics.
getWidth() and Gdx.graphics.getHeight().
Querying the FPS (frames per second) counter查询帧数
Query a built-in frame counter provided by Libgdx to find the average number of
frames per second by calling Gdx.graphics.getFramesPerSecond().
The files module
The files module can be accessed either through Gdx.getFiles() or by using the
shortcut variable Gdx.files./*现在基本都用这个,加括号的getFiles()已被抛弃*/
Getting an internal file handle获取内部文件
You can get a file handle for an internal file by calling Gdx.files.internal(filename).
An internal file is relative to the assets folder on the Android and WebGL
platforms. On a desktop, it is relative to the root folder of the application.
Getting an external file handle获取外部文件
You can get a file handle for an external file by calling Gdx.files.external(filename).
An external file is relative to the SD card on the Android platform. On a
desktop, it is relative to the user's home folder. Note that this is not available
for WebGL applications.
网络模块和声音模块没讲,比较简单,可自行翻阅文档