在我的比赛,当我点击一个按钮,弹出就会出来。是否有可能不使用图像绘制一个透明层?-LibGdx
同时,我想,在除了弹出屏幕画一个透明层,使像而弹出是积极的印象,背景被禁用。
事情是这样的:
是否有可能使现有的固体图像创建一个透明覆盖?
或
我应该使用一个透明的图像本身进行透明层的印象如何?
在我的比赛,当我点击一个按钮,弹出就会出来。是否有可能不使用图像绘制一个透明层?-LibGdx
同时,我想,在除了弹出屏幕画一个透明层,使像而弹出是积极的印象,背景被禁用。
事情是这样的:
是否有可能使现有的固体图像创建一个透明覆盖?
或
我应该使用一个透明的图像本身进行透明层的印象如何?
Image
是一个Actor
可以得出,但你需要透明度的演员,用Actor
。
创建一个Actor
透明层和正确的顺序添加,使您可以禁用只背景演员触摸。
你应该保持演员的秩序。
stage=new Stage();
Texture texture=new Texture("badlogic.jpg");
Image image=new Image(texture);
image.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("TouchTest","Clicked on Image");
}
});
stage.addActor(image);
Actor actor=new Actor(); // this is your transparent layer
actor.setSize(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
stage.addActor(actor);
// Popup should on the top or your actor(touch layer)
Image image1=new Image(texture);
image.setPosition(100,100);
stage.addActor(image1);
Gdx.input.setInputProcessor(stage);
您还可以管理你的触摸层的touchability。
actor.setTouchable(Touchable.disabled); // when you want to disable touch on
在我的建议,你应该使用Dialog
为你弹出。对话框是一个包含内容表的模式窗口。
编辑
从您的参考图像这似乎是你需要半透明层,使用semiTL
代替Actor
在上面的代码。
Pixmap pixmap = new Pixmap(1,1, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.BLACK);
pixmap.fillRectangle(0, 0, 1, 1);
Texture texture1=new Texture(pixmap);
pixmap.dispose();
Image semiTL=new Image(texture1);
semiTL.setSize(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
semiTL.getColor().a=.8f;
stage.addActor(semiTL);
渲染shapeRenderer矩形,将颜色更改为透明。检查[this](https://stackoverflow.com/questions/15397074/libgdx-how-to-draw-filled-rectangle-in-the-right-place-in-scene2d)主题 – Squiddie