2016-06-09 32 views

回答

0

ImageTextButton怎麼樣?

或者你使用一個按鈕,並添加一個堆棧(持有多個項目,你可以置身其中個體經營)

我不建議你,做你自己的按鈕。你會重新發明輪子。

我建議:嘗試ImageTextButton。
如果不幫助 - >按鍵+堆棧

0
public class TextureActor extends Actor { 

    private Texture texture; 

    public TextureActor(Texture texture) { 
     this.texture = texture; 
    } 

    @Override 
    public void draw(Batch batch, float parentAlpha) { 
     batch.draw(texture, getX(), getY(), getWidth(), getHeight()); 
    } 
} 

你當然可以與任何其他可以通過批量繪製更換Texture。或者使用另一個draw方法和更詳細的參數。

+0

所以我做了這樣的事情,但我堅持讓它來處理點擊事件。我試過使用ClickedListener,但它似乎沒有工作。我不確定這是因爲我做錯了什麼,或者我根本無法將ClickListener添加到Actor對象(這對我來說沒有任何意義)。 –

+0

ClickListener應該適用於任何Actor。 – Tenfour04

+0

也許你忘了設置Touched(Touchable.enabled); –

0

按鈕實際上並不需要的皮膚,所以會容易得多隻是做一個工廠方法來簡化它,而不是代碼的所有適當的按鈕的邏輯:

public static Button makeButton (TextureRegion upImage, TextureRegion downImage, Actor contentActor) { 
    Button.ButtonStyle style = new Button.ButtonStyle(); 
    style.up = new TextureRegionDrawable(upImage); 
    style.down = new TextureRegionDrawable(downImage); 
    return contentActor == null ? new Button(style) : new Button(contentActor, style); 
}