如何使用Pixmap纹理处理libGDX图像的恢复

如何使用Pixmap纹理处理libGDX图像的恢复,libgdx,Libgdx,我有一个com.badlogic.gdx.scenes.scene2d.ui.Image,它是从Pixmap构建的。Pixmap只有一个像素,因为我用它来构建一个可以淡入淡出的背景图像 Pixmap pmap=新的Pixmap(1,1,Pixmap.Format.rgba888); pmap.setColor(1.0f、1.0f、1.0f、1.0f); pmap.drawPixel(0,0); bgImage=新图像(新纹理(pmap)); pmap.dispose(); bgImage.set

我有一个com.badlogic.gdx.scenes.scene2d.ui.Image,它是从Pixmap构建的。Pixmap只有一个像素,因为我用它来构建一个可以淡入淡出的背景图像

Pixmap pmap=新的Pixmap(1,1,Pixmap.Format.rgba888);
pmap.setColor(1.0f、1.0f、1.0f、1.0f);
pmap.drawPixel(0,0);
bgImage=新图像(新纹理(pmap));
pmap.dispose();
bgImage.setSize(MyGame.virtual_WIDTH,MyGame.virtual_HEIGHT);
bgImage.getColor().a=0.0f;
bgImage.addAction(Actions.sequence(Actions.fadeIn(1.0f)、Actions.delay(3.0f)、Actions.fadeOut(1.0f));
stage.addActor(bgImage);

它工作得很好,但我担心的是,当动作发生时,游戏可能会暂停。我假设操作将在恢复时继续,因此我需要保留相同的映像,但底层的Pixmap未被管理,因此需要在恢复时重新创建。我不知道如何将纹理/像素贴图重新附着到图像。构建Pixmap本身很容易,但要使用现有的映像却是个问题。

映像上没有
setTexture
方法。查看它,将纹理包裹在可绘制区域中:

this(new TextureRegionDrawable(new TextureRegion(texture)));
因此,您可以执行类似的操作,并使用该方法更改所使用的可绘制对象。大概是这样的:

bgImage.setDrawable(new TextureRegionDrawable(new TextureRegion(new Texture(pmap))));

我认为您可能可以重用
TextureRegion
及其所有容器(因此,在生成新的pixmap后,只需将其包装在
Texture
中,并在暂停之前将其推入保存的
TextureRegion

我的解决方案如下

假设Pixmap Pixmap=

TextureData texData = new PixmapTextureData(pixmap, Format.RGBA8888, false, false, true);
Texture texture = new Texture(texData);
Image image = new Image(texture);
PixmapTextureData中的最后一个标志是“托管”。它在我的上运行


您可以查看以下链接的第一部分,查看哪些是管理的,哪些不是。

我没有创建或保存TextureRegion,但如果我创建或保存了它,它似乎可以工作:((TextureRegionRavable)bgImage.getDrawable()).setRegion(new TextureRegion(new Texture(pmap)));我相信您需要使用夜间版本来实现这一点-我不认为在稳定版本中这是一个选项。