首页 > 代码库 > 【开源java游戏框架libgdx专题】-05-模块描述与上下文

【开源java游戏框架libgdx专题】-05-模块描述与上下文

  1. 模块描述(Modules overview)
  • Input:为所有的平台提供一个统一的输入模型和处理程序。
获取触摸示例:
1  if (Gdx.input.isTouched()) {2    System.out.println("Input occurred at x="+Gdx.input.getX() +", y="+Gdx.input.getY()); 3 }
    • Graphics:能够使用硬件提供的OpenGL ES在屏幕上绘制图片
获取OpenGL API 2.0实现,如果硬件不支持OpenGL ES 2.0将返回Null
1 GL20 gl =Gdx.graphics.getGL20 ();2 gl.glClearColor(1f, 0.0f, 0.0f, 1);3 gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

 

    • Files:在所有平台上的文件访问提供方便的方法读和写。
从文件$APP_DIR/assets/textures 中创建纹理示例:
1 Texture myTexture =newTexture(Gdx.files.internal(“assets/texture/brick.png”));
    • Audio:在所有平台上播放和记录声音
播放声音示例:
1 Music music =Gdx.audio.newMusic(Gdx.files.getFileHandle("data/myMusicFile.mp3", FileType.Internal));2 music.setVolume(0.5f);3 music.play();4 music.setLooping(true);
    • Networking:提供执行网络操作的方法。
    • 基本游戏框架
技术分享
  1. 应用环境的获取(上下文)
    1. 获取应用程序类型
1 switch (Gdx.app.getType()) {2     case Android:// android specific codebreak; 3     case Desktop:// desktop specific codebreak;4     case WebGl:// HTML5 specific codebreak;5     default:// Other platforms specific code6 }
如果是安卓程序还可以获取安卓的版本:
1 int androidVersion =Gdx.app.getVersion();
    1. 内存消耗情况
下面两种方法获取java和本地的内存可用情况
1 long javaHeap =Gdx.app.getJavaHeap();2 long nativeHeap =Gdx.app.getNativeHeap();

原文由博主 乐智 编辑撰写,版权归博主所有。

原文地址 http://www.dtblog.cn/1126.html 转载请注明出处!

【开源java游戏框架libgdx专题】-05-模块描述与上下文