Reputation: 49
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?
Upvotes: 4
Views: 6722
Reputation: 5597
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);
Upvotes: 1
Reputation: 29150
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:
Upvotes: 1