如何处理具有Pixmap纹理的libGDX图像的简历 [英] How to handle resume for libGDX Image with Pixmap texture
问题描述
我有一个从Pixmap构建的com.badlogic.gdx.scenes.scene2d.ui.Image. Pixmap仅为一个像素,因为我正在使用它来构建一个图像,该图像用作可以淡入和淡出的背景.
I have a com.badlogic.gdx.scenes.scene2d.ui.Image that is built from a Pixmap. The Pixmap is only one pixel because I'm using it to build an Image that functions as a background that can fade in and out.
Pixmap pmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pmap.setColor(1.0f, 1.0f, 1.0f, 1.0f);
pmap.drawPixel(0, 0);
bgImage = new Image(new Texture(pmap));
pmap.dispose();
bgImage.setSize(MyGame.VIRUAL_WIDTH, MyGame.VIRUAL_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);
效果很好,但我担心的是在进行动作时可能会暂停游戏.我认为操作将在恢复后继续进行,因此我需要保留相同的Image,但是底层Pixmap未被管理,因此需要在恢复时重新创建.我在弄清楚如何将Texture/Pixmap重新附加到图像时遇到了麻烦.构建Pixmap本身很容易,但是要使用现有的Image就是一个问题.
It works great but my concern is that the game might be paused while the actions are taking place. I assume the actions will continue upon resuming so I need to keep the same Image but the underlying Pixmap is not managed and therefore needs to be recreated upon resume. I'm having trouble figuring out how to reattach the Texture/Pixmap to the Image. Building the Pixmap itself is easy but getting an existing Image to use it is the problem.
推荐答案
Image
上没有setTexture
方法.查看 Image(Texture)
构造函数将纹理包裹在可绘制区域中:
There is no setTexture
method on an Image
. Looking at the Image(Texture)
constructor it wraps the texture in a drawable region:
this(new TextureRegionDrawable(new TextureRegion(texture)));
So you can do something similar and use the Image.setDrawable
method to change the drawable object used. Something like this:
bgImage.setDrawable(new TextureRegionDrawable(new TextureRegion(new Texture(pmap))));
我认为您可能可以重用TextureRegion
及其所有容器(因此,在生成新的像素图后,只需将其包装在Texture
中,然后从暂停之前将其推入保存的TextureRegion
中即可.
I think you can probably reuse the TextureRegion
and all of its containers (so after generating a new pixmap, just wrap it in a Texture
and push that into the saved TextureRegion
from before the pause.
这篇关于如何处理具有Pixmap纹理的libGDX图像的简历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!