3

Ok I have been searching so long for this, and I can never seem to find a good solution for my problem. I know that the TextArea class in libgdx is used for user input. People use it so that user can input multiple lines of a String. I need something like a TextArea that does the opposite. I want to display text to the user in a specific area for (Just like the text area), but I want it to be in some sort of window within my game (kinda like a table or a dialog box only without prompting the user for input). Can ANYONE help me with this? or is this something I just have to make from scratch?

Luis Torres
  • 39
  • 1
  • 8
  • 1
    In your extensive searching, I think you forgot to look at the LibGDX documentation. :) https://github.com/libgdx/libgdx/wiki/Scene2d.ui#label https://github.com/libgdx/libgdx/wiki/Bitmap-fonts – Tenfour04 Jul 28 '16 at 18:31
  • labels don't do what I want – Luis Torres Jul 28 '16 at 18:34
  • Also I know about the bitmap fonts. I am fine with using bitmap fonts. I just need a container for my text. A label is ugly and when I need it to print a new line it moves the previous text upwards. I want a container that will print a new line under the previous line when it is necessary. It's a lot like TextArea, but it is for output as opposed to input – Luis Torres Jul 28 '16 at 18:44
  • Wrap the Label in a Table or Container and bias it to the top of its Cell (or the Container). Not sure what you mean by a Label being ugly. – Tenfour04 Jul 28 '16 at 18:58
  • but I want it to also be a sort of window or box that text is contained in. what I mean by ugly is that it is the text is just sorta there in my game. I don't want to just display text on a blank screen. that's easy. What I need is something like a TextArea that is used for output instead of input – Luis Torres Jul 28 '16 at 19:13
  • You can set a background Drawable on the Table that contains it. – Tenfour04 Jul 28 '16 at 19:15
  • Hmm...That may work. I will try that if there really is no other way to do it. It just surprises me that so many games have this yet there doesn't seem to be an intuitive way to implement it. – Luis Torres Jul 28 '16 at 19:29

2 Answers2

1

Using gdxVersion = '1.4.1' (built with gradle in Android Studio) that code draws text successfully:

BitmapFont font = new BitmapFont(); //or use alex answer to use custom font

public void render( float dt )
  {
    batch.setProjectionMatrix(camera.combined); //or your matrix to draw GAME WORLD, not UI

    batch.begin();
    //draw background, objects, etc.
    for( View view: views )
    {
      view.draw(batch, dt);
    }

    font.draw(batch, "Hello World!", 10, 10);
    batch.end();
  }

Credit goes to @Deepscorn

For more you can go through this tutorials:

  1. Libgdx tutorial for simply display the words Hello World on screen.
  2. How can I draw text using Libgdx/Java?
  3. libGDX - Add scores & display it at top left corner of the screen?
Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • Not quite. The thing I like about the text Area is that I can give it a sort of image property, so that I can draw an image on the screen with some text in it. I need to do that but not have it so that it takes input. instead it just outputs text to the user – Luis Torres Jul 28 '16 at 18:40
1

You can use the Label class and set a background drawable in the LabelStyle:

Label.LabelStyle style = new LabelStyle();
style.background = ...; // Set the drawable you want to use

Label label = new Label("Text here", style);
manabreak
  • 5,415
  • 7
  • 39
  • 96