libgdx The application frame working

本文档详尽地介绍了LibGDX游戏开发框架的各项功能与使用方法,包括但不限于项目搭建、第三方服务集成、图形渲染、音频处理等核心模块。通过实际代码示例展示了如何根据运行平台的不同调整应用行为,并提供了查询应用程序内存占用的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Table of Contents

a note from the translation

Wiki Style Guide

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 {

	
	@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

	}

}

下载链接:

http://download.youkuaiyun.com/detail/caihongshijie6/7035857

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值