2017-05-02 16 views
0

私は背景色とアウトラインのさまざまな組み合わせで、ボタンの膨大な配列を生成する必要があるゲームを設計しています。私はすでに背景用のスプライトと輪郭用のスプライトを持っており、それぞれに色合いを適用します。LibGDXで複数のスプライト/テクスチャレイヤを持つImageButtonを作成するにはどうすればよいですか?

私はすでに両方のSpriteBatchに参加しようとしましたが、ImageButtonがサポートしている構造に変換することはできませんでした。

ありがとうございます。

答えて

0

ImageButtonの独自のバージョンを作成するには、Actorクラスを拡張し、独自の描画メソッドを実装します。以下の例は、テストされていませんが、独自のカスタムボタンを作成する方法であなたとアイデアを与える必要があります:

private class LayeredButton extends Actor{ 
    private int width = 100; 
    private int height = 75; 
    private Texture backGround; 
    private Texture foreGround; 
    private Texture outline; 

    public LayeredButton(Texture bg, Texture fg, Texture ol){ 
     setBounds(this.getX(),this.getY(),this.width,this.height); 
     backGround = bg; 
     foreGround = fg; 
     outline = ol; 
     addListener(new InputListener(){ 
      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { 
       // do something on click here 
       return true; 
      } 
     }); 
    } 
    @Override 
    public void draw(Batch batch, float alpha){ 
     // draw from back to front 
     batch.draw(backGround,this.getX(),this.getY()); 
     batch.draw(foreGround,this.getX(),this.getY()); 
     batch.draw(outline,this.getX(),this.getY()); 
    } 

    @Override 
    public void act(float delta){ 
     // do stuff to button 
    } 
} 
+0

'draw'メソッドをオーバーライドし、実際に見事にシンプルなアイデアだこと。どうもありがとうございました。 –

関連する問題