2017-05-30 43 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

相關問題