libgdx The application frame working

来源:互联网 发布:羽绒被 蚕丝被 知乎 编辑:程序博客网 时间:2024/05/22 09:00

Table of Contents

a note from the translation

Wiki Style Guide

  • 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
    • Third Party Services
      • AdMob in Libgdx
      • Swarm in Libgdx
      • NextPeer in Libgdx
      • Google Play Game Services in LibGDX
    • Working from Source
      • Running Demos & Tests
      • Building libgdx from Source
    • Using libgdx with other JVM languages
      • Using libgdx with Clojure
      • Using libgdx with Python
      • Using libgdx with Scala
    • The Application Framework
      • The Life-Cycle
      • Modules Overview
      • Starter Classes & Configuration
      • Querying
      • Logging
      • Threading
      • Interfacing with Platform-specific Code
    • A Simple Game
      • Extending the Simple Game
    • File Handling
    • Networking
    • Preferences
    • Input Handling
      • Configuration & Querying
      • Mouse, Touch & Keyboard
        • Polling
        • Event Handling
      • Controllers
      • Gesture Detection
      • Simple Text Input
      • Accelerometer
      • Compass
      • Vibrator
      • Cursor Visibility & Catching
      • Back and Menu Key Catching
      • On-screen Keyboard
    • Memory Management
    • Audio
      • Sound Effects
      • Streaming Music
      • Playing PCM Audio
      • Recording PCM Audio
    • Graphics
      • 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
          • Rendering Shapes
          • Textures & TextureRegions
          • Meshes
          • Shaders
          • Frame Buffer Objects
      • 2D Graphics
        • SpriteBatch, TextureRegions, and Sprite
        • 2D Animation
        • Clipping, with the use of ScissorStack
        • Orthographic camera
        • Mapping Touch Coordinates ??
        • NinePatches
        • Bitmap Fonts
          • Distance field fonts
        • Using TextureAtlases
        • Pixmaps
        • Packing Atlases Offline
        • Packing Atlases at Runtime
        • 2D Particle Effects
        • Tile Maps
        • scene2d
          • scene2d.ui
          • Skin
      • 3D Graphics
        • Quick Start
        • Models
        • Material and environment
        • 3D animations and skinning
        • Importing Blender models in LibGDX
        • Perspective Camera ??
        • Picking ??
    • Managing Your Assets
    • Utilities
      • Reading & Writing JSON
      • Reading & Writing XML
      • Collections
      • Reflection
      • jnigen
    • Math Utilities
      • Interpolation
      • Vectors, Matrices, Quaternions
      • Circles, Planes, Rays, etc.
      • Path interface & Splines
      • Bounding Volumes ??
      • Intersection & Overlap Testing ??
    • Physics
      • Box2D
      • Bullet Physics
    • Tools
      • Texture Packer
      • Hiero
      • Particle Editor
    • Extensions
      • gdx-audio
      • gdx-freetype
    • Deploying your Application
    • Building Libgdx ??
    • Known Issues
  • Articles
    • Getting Help
    • External Tutorials
    • Bundling a JRE
    • Saved Game Serialization
  • Deprecated (May be outdated)
    • Graphics Module
      • Screen & Viewport
    • Misc
      • Integrating Libgdx and the Device camera

The Application interface provides various methods to query properties of the run-time environment.

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() method returns the platform the application is currently running on:

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 {@Overridepublic 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 levelSystem.out.println("运行所运行的游戏的平台是: " + androidVersion);    //对本app占用内存的状况的查询long javaHeap = Gdx.app.getJavaHeap();//获取javaheaplong nativeHeap = Gdx.app.getNativeHeap();//获取本地heapSystem.out.println( "javaHeap: "+ javaHeap);System.out.println( "nativeHeap: "+ nativeHeap);}@Overridepublic void dispose() {// TODO Auto-generated method stub}@Overridepublic void pause() {// TODO Auto-generated method stub}@Overridepublic void render() {Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);}@Overridepublic void resize(int arg0, int arg1) {// TODO Auto-generated method stub}@Overridepublic void resume() {// TODO Auto-generated method stub}}

下载链接:

http://download.csdn.net/detail/caihongshijie6/7035857

0 0