当前位置:编程学习 > wap >>

Libgdx中的TextureRegion.split方法的问题


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

public class SpriteAnimation implements ApplicationListener {

private static final int FRAME_COLS = 6;  
private static final int FRAME_ROWS = 5;  

Animation walkAnimation;  
Texture walkSheet; 
TextureRegion[] walkFrames; 
SpriteBatch spriteBatch; 
TextureRegion currentFrame; 
TextureRegion[][] tmp;
float stateTime; 

@Override
public void create() {
walkSheet = new Texture(Gdx.files.internal("data/animation_sheet.png")); //图片宽,高都要是2的整数幂次方才行

tmp = TextureRegion.split(walkSheet, 
(Integer)(walkSheet.getWidth()/ FRAME_COLS),
(Integer)(walkSheet.getHeight() / FRAME_ROWS)); 


walkFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS];
int index = 0;
for (int i = 0; i < FRAME_ROWS; i++) {
for (int j = 0; j < FRAME_COLS; j++) {
walkFrames[index++] = tmp[i][j];
}
}
walkAnimation = new Animation(3f, walkFrames); 
spriteBatch = new SpriteBatch(); 
stateTime = 0f;

}

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

}

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

}

@Override
public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
        stateTime += Gdx.graphics.getDeltaTime();                       
        currentFrame = walkAnimation.getKeyFrame(stateTime, true);      
        
spriteBatch.begin();
        spriteBatch.draw(currentFrame, 50, 50);             
        spriteBatch.end();
        
}

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

}

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

}

}



一个行走的动画,6*5的30个动作 总是走完上面第一排前6个动作 后面就是空了。然后一会儿又走6个动作。。。 输出TextureRegion.split()拿到的值 不是空的 但是画面是空的 这是libgdx官方给的代码 那位大神能给解决下 谢谢
补充:移动开发 ,  Android
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,