本文实例讲述了Android使用libgdx实现模拟方向键控制角色移动的方法。分享给大家供大家参考,具体如下:
package com.demo;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
//Libgdx的Texture与Sprite使用
public class LibgdxActivity extends AndroidApplication {
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
// 初始化游戏屏幕,并设置是否支持GLES 2.0,如果您对向下兼容没什么需要选择true即可(2.1以上),否则选择false。
// initialize(new FirstGame(), true);
initialize(new Box2DDemo(), true);
}
}
package com.demo;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
public class FirstActor extends Actor{
private Texture texture;
@Override
public void draw(SpriteBatch batch, float arg1) {
batch.draw(texture, this.x, this.y);
}
@Override
public Actor hit(float arg0, float arg1) {
if (x > 0 && y > 0 && this.height > y && this.width > x) {
<