Search code examples
javalabeltooltiplibgdx

Libgdx show tooltip


I am developing a game with libgdx. This game contains different Levels, which are rendered by a Stage. All objects in that Level are represented by libgdx Actors. Now I want to have a tutorial Level. In this Level a tooltip should show when the Player reaches a specific Position within the Level. This tooltip should contain informations (like: "Press A to go left!") and dissapear after some time. I thought about using libgdx Label and add a Sequence of Actions to them (•Delay 5s •FadeOut in 1s). The Problem is that for Labels I need to create a LabelStyle for which I have to create a Font file and load it. Is there a way to create a Label with a default font (like ARIAL or others)? It should just be easy to read nothing more. Or is there another easy way to create this kind of tooltips?


Solution

  • Be careful how you're using the term "tooltip". I don't think what you're talking about is actually a tooltip, just a message displayed on the screen.

    If you want to display text in libGDX, you should do the work and use a real font. But for quick-and-dirty rendering, you can use the BitmapFont class. Something like this:

    BitmapFont font = new BitmapFont();
    font.setColor(Color.WHITE);
    font.setScale(2f);
    font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 25, 25);