我有一个图像,它由块(32 * 32)组成,有1行和4列。我该怎么办,当我加载纹理时,我只加载一个块而不是全部4个块?
答案 0 :(得分:2)
方法1)
Texture texture=new Texture(Gdx.files.internal("ui/logo2.png"));
Sprite sprite=new Sprite(texture);
sprite.setRegion(0, 0, 1f/4f, 1);//this loads the first block
sprite.setRegion(1f/4f, 0, 1f/4f+1f/4f, 1);//this loads the second block
sprite.setRegion((1f/4f)*2, 0, 1f/4f+(1f/4f)*2, 1);//this loads the third block
//on render
sprite.draw(theSpriteBatch);
方法2)
Texture texture=new Texture(Gdx.files.internal("ui/logo2.png"));
TextureRegion[][] tmp = TextureRegion.split(texture, 32, 32);
Sprite sprite=new Sprite(tmp[0][0]);//first
Sprite sprite=new Sprite(tmp[0][1]);//second
Sprite sprite=new Sprite(tmp[0][2]);//third
//on render
sprite.draw(yourSpriteBatch);