libgdx的使用--环境搭建测试

首先在eclise中创建android工程
new-->project-->android project.最低兼容版本选择1.5最高一般选择3.2 theme选项 选择holo light;

默认的类名为MainActivity.java 将其继承AndroidApplication类,此类作为主线程
新建一个类 名为HelloGame类实现ApplicationListener接口,声明私有变量SpriteBatch,并在create()函数中将私有变量SpriteBatch实例化,并且在render()函数中设置SpriteBatch的开始与结束.
运行android虚拟机 将看到只是一个黑框.
MainActivity.java可运行代码如下:
package com.FLM.helloworld;

import com.badlogic.gdx.backends.android.AndroidApplication;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends AndroidApplication {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
        initialize(new FirstGame(), false);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}


下面是HelloGame.java的代码
package com.FLM.helloworld;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class FirstGame implements ApplicationListener {
private SpriteBatch batch;

@Override
public void create() {
// TODO Auto-generated method stub
batch=new SpriteBatch();

}

@Override
public void dispose() {
// TODO Auto-generated method stub

}

@Override
public void pause() {
// TODO Auto-generated method stub


}

@Override
public void render() {
// TODO Auto-generated method stub
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); //清屏
batch.begin();
batch.end();

}

@Override
public void resize(int arg0, int arg1) {
// TODO Auto-generated method stub

}

@Override
public void resume() {
// TODO Auto-generated method stub

}

}

参考:http://www.cnblogs.com/htynkn/archive/2011/11/10/libgdx_1.html

你可能感兴趣的:(libgdx)