2017-05-30 67 views
0

在我的比赛,当我点击一个按钮,弹出就会出来。是否有可能不使用图像绘制一个透明层?-LibGdx

同时,我想,在除了弹出屏幕画一个透明层,使像而弹出是积极的印象,背景被禁用。

事情是这样的:

enter image description here

是否有可能使现有的固体图像创建一个透明覆盖?


我应该使用一个透明的图像本身进行透明层的印象如何?

+0

渲染shapeRenderer矩形,将颜色更改为透明。检查[this](https://stackoverflow.com/questions/15397074/libgdx-how-to-draw-filled-rectangle-in-the-right-place-in-scene2d)主题 – Squiddie

回答

2

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); 
+0

谢谢你。答案是丰富的对于实际创建layer.But我的问题是关于从现有image.May创建一个透明覆盖是我的问题是不clear.Now编辑讲清楚。 – Niranjana

+0

@Niranjana我编辑了我的答案,请检查 – Aryan

相关问题