1
\$\begingroup\$

I have the button:

soundBtnStyle = new ImageButton.ImageButtonStyle();
    soundBtnStyle.up = skinBac.getDrawable("on");//
    soundBtnStyle.down = skinBac.getDrawable("off"); //

    soundsButton = new ImageButton(soundBtnStyle);
    soundsButton.setSize(120, 120);

    soundsButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.rainMusic.setVolume(0.0f);
        }
    });

call the button in the constructor,I can not figure out how to add a button to the stage.

game.batch.begin();
    game.batch.draw(soundsButton, 0, 0,120, 120);
game.batch.end();
enter code here

It does not work, an error enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ What is the error? \$\endgroup\$ Jul 24, 2016 at 5:48
  • \$\begingroup\$ @ SurvivalMachine update question \$\endgroup\$
    – upward
    Jul 24, 2016 at 6:40

3 Answers 3

1
\$\begingroup\$

If only there was a magical place where you could look up things like this.

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ImageButton.html#draw-com.badlogic.gdx.graphics.g2d.Batch-float-

I wonder if that button classes draw routine could help. Hmmmmmm.

\$\endgroup\$
0
\$\begingroup\$

Right after you create a new ImageButton you can add it like:

soundsButton = new ImageButton(soundBtnStyle); soundsButton.setSize(120, 120); //add button here stage.addActor(soundsButton); //set position at x=0 & y=0 as soundButton.setPosition(0,0);

\$\endgroup\$
0
\$\begingroup\$

The draw() method only accepts Texture and TextureRegion. You're passing an ImageButton. ImageButton is an Actor and is part of Scene2d and they are usually used along with Screen, Game and Stage. You should check this tutorial to know more about Scene2D.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .