How do I combine the Android UI buttons with libGDX?

I want to combine the Android UI with libGDX. I want to have half of my screen drawing an animated sprite with the libGDX engine, and the other half of the screen drawing Android UI buttons.

How do I combine the Android UI buttons with libGDX?


Libgdx has a great UI package called scene2d. It is specially written for UIs, but can be used for other things also.

See Scene2d.ui documentation

What you will want to do is create a UI stage. During your game loop call stage.draw() after you draw your game so it renders over the top of your game. If you just want to use the UI to receive input then just use Gdx.input.setInputProcessor(...) to set the UI stage as the input processor. If you want the game and the stage to receive input you will need to use an InputMultiplexer.

You add widgets (widgets being things like tables, buttons, and more) to the stage. And then add change listeners to the particular widgets to help control your game.

Source : Link , Question Author : Dexter , Answer Author : Piro says Reinstate Monica

Leave a Comment