Application接口提过多种方法查询运行时环境属性。
有时候根据运行平台需要处理一些具体的逻辑,可以使用 Application.getType() 方法来返回应用所运行的平台:
switch (Gdx.app.getType()) { case Android: // android specific code break; case Desktop: // desktop specific code break; case WebGl: // HTML5 specific code break; default: // Other platforms specific code }
在Android上,还可以查询Android版本:
int androidVersion = Gdx.app.getVersion();
将返回SDK level,例如对Android 1.5,返回值为3.
为调试或分析需要,常常需要知道内存消耗状况,包括Java heap和Native heap:
long javaHeap = Gdx.app.getJavaHeap(); long nativeHeap = Gdx.app.getNativeHeap();
两个方法都返回在相应的堆中使用的字节数。
Application借口提供简单的日志功能。记录的消息可以是info,error或debug:
Gdx.app.log("MyTag", "my informative message"); Gdx.app.error("MyTag", "my error message", exception); Gdx.app.debug("MyTag", "my error message");
根据平台,消息会记录到终端(Desktop),LogCat(Android)或一个由GwtApplicationConfiguration提供的GWT TextArea,或由html5自动创建。
可以限制具体日志级别:
Gdx.app.setLogLevel(logLevel);
其中logLevel可以是如下值:
Libgdx 开发指南(1.3) 应用框架——查询、日志,布布扣,bubuko.com
原文:http://www.cnblogs.com/sunshy/p/3642392.html