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.bison.gdxlearn;
-
- import android.os.Bundle;
-
- import com.badlogic.gdx.backends.android.AndroidApplication;
-
- public class LearnGdxActivity extends AndroidApplication {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- initialize(new Game(), false);
- }
- }
新建一个Game类:
- package com.bison.gdxlearn;
-
- import javax.microedition.khronos.opengles.GL10;
-
- import com.badlogic.gdx.ApplicationListener;
- import com.badlogic.gdx.Gdx;
- 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, 200, 30);
-
- batch.end();
- }
-
- @Override
- public void resize(int arg0, int arg1) {
-
- }
-
- @Override
- public void resume() {
-
- }
-
- }
其中在assets文件中添加一张图片,图片的尺寸为2的n次方,如:64x256,128x256 etc.
4.运行
libDGX 的详细介绍:请点这里
libDGX 的下载地址:请点这里