1.首先下载libgdx文件....
http://code.google.com/p/libgdx/downloads/list
解压后会看见许多的jar文件,在Android工程中会用到gdx.jar和gdx-backend-android.jar
2.新建一个Android工程.....
在工程项目文件下新建一个libs目录
将gdx.jar和gdx-backend-android.jar文件copy到此目录,
并右键--->Build Path--->Add to Build Path..........
将下载的libgdx.zip文件中解压出来的 armeabi 和 armeabi-v7a 两个文件夹copy到libs目录.
这样,基本环境搭建完毕!例如下图:
3.测试改写主Activity 类,让其extends AndroidApplication如:
package com.mzz.testlibgdx; import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; public class MainActivity extends AndroidApplication { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initialize(new Game(), false); } }
新建一个Game类:
package com.mzz.testlibgdx; import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; public class Game implements ApplicationListener { //绘图工具 private SpriteBatch batch ; //图片解码类 private Texture texture ; @Override public void create() { //实例化 batch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("basketball.png")); } @Override public void dispose() { } @Override public void pause() { } @Override public void render() { //清屏 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); //开始 batch.begin(); //绘制图片 batch.draw(texture, 100, 100); //结束 batch.end(); } @Override public void resize(int arg0, int arg1) { } @Override public void resume() { } }
其中在assets文件中添加一张图片,图片的尺寸为2的n次方,如:64x256,128x256 etc.