我正在使用libGDX构建一个小游戏,目前正在尝试在屏幕上显示动画。目前它只显示动画的第一帧。
我正在使用线程进行更新和渲染(这是我怀疑问题所在的地方)
public class SuperBoopers extends Game implements ApplicationListener {
public static final int V_WIDTH = 480;
public static final int V_HEIGHT = 600;
public SpriteBatch batch;
FieldScreen screen;
private PauseableThread thread;
private boolean running = false;
@Override
public void create () {
batch = new SpriteBatch();
screen = new FieldScreen(this);
setScreen(screen);
running = true;
thread = new PauseableThread(new Runnable() {
long timeLast = System.nanoTime();
final double ticks = 60D;
double ns = 1000000000 / ticks;
float dt = 0;
@Override
public void run() {
while (running){
long timeNow = System.nanoTime();
dt += (timeNow - timeLast)/ns;
timeLast = timeNow;
if(dt >= 1) {
update();
render(dt);
}
}
}
});
}
private void update(){
screen.update();
}
public void render (float dt) {
screen.render(dt);
}
这是动画对象的类
public class Actor {
private static Texture atlas = new Texture("Atlas.png");
private Sprite sprite;
private int frames; //number of total frames for the animation
private int frameNumber; //current frame number
private int xi; //x location of the first frame in the texture atlas
private int yi; //y location of the first frame in the texture atlas
private int frameSize; //standard size of a single square frame in pixels
public Actor(int frames, int xi, int yi){
this.frames = frames;
this.xi = xi;
this.yi = yi;
frameNumber = 0;
frameSize = 64;
sprite = new Sprite(new TextureRegion(atlas, xi, yi, frameSize, frameSize));
}
public void update(){
//checks what frame it's on, if was last frame, resets frame number
if(frameNumber == frames-1){
frameNumber = 0;
} else {frameNumber++;}
//scoots the TextureRegion forward the distance of one frameSize
sprite.setRegionX(xi+(frameSize*frameNumber));
}
public void draw(SpriteBatch batch){
sprite.draw(batch);
}}
我知道我可能会遗漏一些非常大而且显而易见的东西。