我为自己写了一个小游戏,现在我遇到了需要将两个TextureRegions
放在一个纹理上的问题。我已经用Pixmaps
尝试了它,但它对我不起作用。有没有办法解决这个问题
答案 0 :(得分:0)
您是如何使用Pixmap
的?这非常有效:
Pixmap combinedPixmap = new Pixmap(totalWidth, totalHeight, Pixmap.Format.RGBA8888);
Pixmap pixmap1, pixmap2;
Texture texture1 = Your texture region.getTexture() /* Your texture region 1 */;
Texture texture2 = Your texture region.getTexture() /* Your texture region 2 */;
TextureData data1 = texture1.getTextureData();
TextureData data2 = texture2.getTextureData();
if(!data1.isPrepared()) data1.prepare();
if(!data2.isPrepared()) data2.prepare();
pixmap1 = data1.consumePixmap();
pixmap2 = data2.consumePixmap();
combinedPixmap.drawPixmap(pixmap1, 0, 0);
combinedPixmap.drawPixmap(pixmap2, 100, 0);
Texture finalTexture = new Texture(combinedPixmap);
如果由于某种原因没有,您可以使用Framebuffers
。
FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGBA8888, totalWidth, totalHeight, false);
fbo.begin();
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
spriteBatch.draw(region1, 0, 0);
spriteBatch.draw(region2, 100, 0);
spriteBatch.flush();
fbo.end();
TextureRegion combinedRegion = new TextureRegion(fbo.getColorBufferTexture());
combinedRegion.flip(false, true);
Texture combined = combinedRegion.getTexture();
有关framebuffers的更多信息: