【发布时间】:2016-02-13 22:26:36
【问题描述】:
我有一个图像,它由块 (32*32) 组成,有 1 行和 4 列。我该怎么做,当我加载纹理时,我只加载一个块而不是全部 4 个?
【问题讨论】:
-
你是想在内存中实际只加载这个特定的块,还是只使用这个特定的块作为精灵中的纹理?
-
作为使用精灵批处理渲染的纹理。
我有一个图像,它由块 (32*32) 组成,有 1 行和 4 列。我该怎么做,当我加载纹理时,我只加载一个块而不是全部 4 个?
【问题讨论】:
方法一)
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);
方法二)
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);
【讨论】: