TextureRegion的用法--将大图分割小图片

private Texture texture; 
private SpriteBatch batch;
private TextureRegion[] regions = new TextureRegion[4]; 


@Override
public void create() {
texture = new Texture(Gdx.files.internal("data/tR.png"));
batch = new SpriteBatch();
regions[0] = new TextureRegion(texture, 0, 0, 64, 64);          
        regions[1] = new TextureRegion(texture, 64, 0, 64, 64);     
        regions[2] = new TextureRegion(texture, 0, 64, 64, 64);         
        regions[3] = new TextureRegion(texture, 64, 64, 64, 64);  
}


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


}


@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

batch.begin();  

//注释部分可以用来做动画

// TextureRegion[][] regions = TextureRegion.split(texture, 64, 64);
// for (TextureRegion[] region1 : regions) {
// for (TextureRegion region2 : region1) {
// batch.draw(region2, 75 , 100); 
// }
// }
//  
                         
         for (int i = 0; i < regions.length; i++) {  
                 batch.draw(regions[i], 100 * (i + 1), 200);       
         }  
         batch.end();  
}


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


}


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


}


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


}

你可能感兴趣的:(libgdx,TextureRegion)