如何在LibGDX中创建具有多个精灵/纹理层的ImageButton?

如何在LibGDX中创建具有多个精灵/纹理层的ImageButton?,libgdx,textures,sprite,imagebutton,spritebatch,Libgdx,Textures,Sprite,Imagebutton,Spritebatch,我正在设计一款需要生成大量按钮的游戏,这些按钮具有不同的背景颜色和轮廓组合。我已经有一个雪碧作为背景,一个雪碧作为轮廓,并对每一个应用色调 我已经尝试在SpriteBatch上加入这两者,但没有成功地将其转换为ImageButton支持的结构 提前感谢。通过扩展Actor类并实现自己的绘图方法,您可以制作自己版本的ImageButton。下面的示例未经测试,但应能让您了解如何制作自己的自定义按钮: private class LayeredButton extends Actor{ pr

我正在设计一款需要生成大量按钮的游戏,这些按钮具有不同的背景颜色和轮廓组合。我已经有一个雪碧作为背景,一个雪碧作为轮廓,并对每一个应用色调

我已经尝试在SpriteBatch上加入这两者,但没有成功地将其转换为ImageButton支持的结构


提前感谢。

通过扩展Actor类并实现自己的绘图方法,您可以制作自己版本的ImageButton。下面的示例未经测试,但应能让您了解如何制作自己的自定义按钮:

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
    }
}

这实际上是一个非常简单的想法,覆盖了
draw
方法。非常感谢你。