Search code examples
javalibgdxscene2d

Libgdx UI that show information or text when hovered


I'm making a game using libgdx which has a lot of buttons and text fields, I was wondering if there was a Scene2d widget which the user can hover and then a message shows up, something like this.

enter image description here


Solution

  • These are called Tooltips. There is a built-in one called TextTooltip. If you're using skin, you can create a style like this in Json:

    com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle: {
        default: {label: {font: myFont}, background: myBackgroundDrawable, wrapWidth: 400}
    }
    

    Tooltips actually are a type of Listener that contain a widget that it temporarily can add to the Stage. You add the tooltip to whatever widget you already have in your layout:

    myButton.addListener(new TextTooltip("You can press this", skin));