我想要訪問我的精靈表中的特定行,我對如何做到這一點感到非常困惑。我嘗試修改我發現要完成的教程,但是當我運行代碼時,當我的spritesheet和12列中有五行時,我的動畫數組長度爲0。我的課應該總是用一行信息填充我的動畫數組。這裏是我Animator
類在spritesheet中獲取特定行libgdx java
public Animator(Texture spriteSheet, int cols){
this.walkSheet = spriteSheet;
this.cols = cols;
this.rows = 1;
}
public void create() {
TextureRegion[][] tmp = TextureRegion.split(walkSheet, walkSheet.getWidth()/cols, walkSheet.getHeight()/rows); // #10
walkFrames = new TextureRegion[cols];
anim = new Animation[rows];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
walkFrames[j] = tmp[i][j];
}
anim[i] = new Animation(0.025f, walkFrames);
}
stateTime = 0f; // #13
}
public void render(int index, SpriteBatch spriteBatch, int x, int y, int width, int height) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
stateTime += Gdx.graphics.getDeltaTime();
currentFrame = anim[index].getKeyFrame(stateTime, true);
spriteBatch.draw(currentFrame, x, y, width, height);
}
任何幫助,這將是非常讚賞,因爲我花了這麼多時間試圖弄清楚這一點。
您指定的行數= 1,並且您有5行是正確的?請問爲什麼? –