Querying
Table of Contents
- Developer's Guide
- Introduction
- Goals & Features
- Community & Support
- Contributing
- Games Built with Libgdx
- Prerequisites
- Gradle Project Setup, Running, Debugging and Packaging
- Project Setup, Running & Debugging
- Manual Project Setup
- Maven Integration
- Using libgdx with IntelliJ IDEA
- Using libgdx with Android Studio
- RoboVM Notes
- GWT Notes
- GWT Super Dev Mode
- The Life-Cycle
- Modules Overview
- Starter Classes & Configuration
- Querying
- Logging
- Threading
- Interfacing with Platform-specific Code
- Controllers
- Gesture Detection
- Simple Text Input
- Accelerometer
- Compass
- Vibrator
- Cursor Visibility & Catching
- Back and Menu Key Catching
- On-screen Keyboard
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Take a Screenshot
- OpenGL ES Support
- Configuration & Querying OpenGL ??
- Direct Access ??
- Utility Classes
- 2D Graphics
- SpriteBatch, TextureRegions, and Sprite
- 2D Animation
- Clipping, with the use of ScissorStack
- Orthographic camera
- Mapping Touch Coordinates ??
- NinePatches
- Bitmap Fonts
- Using TextureAtlases
- Pixmaps
- Packing Atlases Offline
- Packing Atlases at Runtime
- 2D Particle Effects
- Tile Maps
- scene2d
- 3D Graphics
- Quick Start
- Models
- Material and environment
- 3D animations and skinning
- Importing Blender models in LibGDX
- Perspective Camera ??
- Picking ??
- Managing Your Assets
- Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path interface & Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Tools
- Extensions
- Deploying your Application
- Building Libgdx ??
- Known Issues
- Articles
- Deprecated (May be outdated)
- Misc
The Application
Getting the Application Type 获取游戏运行的平台类型
Sometimes it is necessary to special case specific parts of an application depending on the platform it is running on. The 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
}
On Android, one can also query the Android version the application is currently running on:
int androidVersion = Gdx.app.getVersion();
This will return the SDK level supported on the current device, e.g. 3 for Android 1.5.
Memory Consumption 查询游戏运行时占用内存的状况
For debugging and profiling purposes it is often necessary to know the memory consumption, for both the Java heap and the native heap:
long javaHeap = Gdx.app.getJavaHeap();
long nativeHeap = Gdx.app.getNativeHeap();
Both methods return the number of bytes currently in use on the respective heap.
demo:
package com.example.groupactiontest;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
public class MyGame implements ApplicationListener {
@Override
public void create() {
switch (Gdx.app.getType()) {//获取libgdx游戏所运行的平台
case Android:
System.out.println("--------->你现在用的是android设备...");
break;
case Desktop:
break;
case WebGL:
break;
default:
}
int androidVersion = Gdx.app.getVersion();//获取你的android设备的SDK版本所对应的API level
System.out.println("运行所运行的游戏的平台是: " + androidVersion);
//对本app占用内存的状况的查询
long javaHeap = Gdx.app.getJavaHeap();//获取javaheap
long nativeHeap = Gdx.app.getNativeHeap();//获取本地heap
System.out.println( "javaHeap: "+ javaHeap);
System.out.println( "nativeHeap: "+ nativeHeap);
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}
@Override
public void resize(int arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
}