My animation is not working 2D動畫,僅顯示靜態圖片。我根據libgdx/wiki的例子做了一切。爲什麼它不起作用?libgdx不工作
public class Thorns extends GameObject implements IGameObject {
Animation<TextureRegion> animation;
private static final int FRAME_COLS = 1, FRAME_ROWS = 2;
public Thorns(Texture texture, Body body) {
super(texture, body,false);
Texture walkSheet = new Texture("Thorns.png");
TextureRegion[][] tmp = TextureRegion.split(walkSheet,
walkSheet.getWidth()/FRAME_COLS,
walkSheet.getHeight()/FRAME_ROWS);
TextureRegion[] walkFrames = new TextureRegion[FRAME_ROWS*FRAME_COLS];
int index = 0;
for (int i = 0; i < FRAME_ROWS; i++) {
for (int j = 0; j < FRAME_COLS; j++) {
walkFrames[index++] = tmp[i][j];
}
}
animation = new Animation<TextureRegion>(1.025f, walkFrames);
}
@Override
public void dispose() {
}
int stateTime;
@Override
public void draw(SpriteBatch spriteBatch) {
stateTime += Gdx.graphics.getDeltaTime();
TextureRegion currentFrame = (TextureRegion) animation.getKeyFrame(stateTime, false);
spriteBatch.draw(currentFrame, body.getTransform().getPosition().x, body.getTransform().getPosition().y);
//drawSprite(spriteBatch);
}
}
動畫不啓動在所有
是您Thorns.png圖像2個圖像並排?你是否在等待1.025秒以查看幀改變?它應該是非循環的,所以它只顯示1.025秒的第一個圖像? – dfour
我的理解動畫根本不會啓動。一切都在第一幀。 環流式更改爲true,沒有任何改變。 – GRbI3yH
我將幀更改時間增加了10.0f,但沒有像以前那樣發生 – GRbI3yH