I am learning libgdx but i am stuck at a point..
I have added a button in my stage , now i want to add a image in the stage so that the image looks as the background image to the button.i mean to say that the button should lie on the image. I have been looking tutorials but not been able to do that.
How can it be done? any help?
A small example :
stage.act(Gdx.graphics.getDeltaTime());
stage.getBatch().begin();
stage.getBatch().draw(background, 0, 0, WORLD_WIDTH, WORLD_HEIGHT);
stage.getBatch().end();
stage.draw();
The only thing you need to do is to draw
the background, before drawing the Button
s.
There are a few possible ways to do that:
- You can add the background as an Image
(subclass of Actor
) to the Stage
and use the z-index
to make sure it is drawn as a background.
- You can get the Stage
s SpriteBatch
(stage.getBatch()
) and use one of its draw
methods to draw the background, before calling stage.draw()
You could also use another SpriteBatch
, but i don't recommend it, as it is a pretty "heavy" object and it is just not neccessaty in this case.
I guess, before calling stage.draw()
you need to call spritebatch.end()
, for the SpriteBatch
you used to draw
the background.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With