Text sizing in android with java and libgdx -


I am creating text in libgx, but there is a problem where the text may be different depending on the phone. For, I change them again on the basis of the screen size, but I can not do it with the text, B Auctions needs wrapping and fitting to call it. Can recommend a better way to draw the text that looks evenly on any mobile screen.

Text Category:

  Expands Public Class Textactor Actor {Bitmap Font Font; String text; Float x = 0; Float y = 0; Float w = 10; Float H = 10; Public Textactor (string text) {font = new bitmap font (Gdx.files.internal ("font.fnt")); This.text = text; } @ Override public empty draw (Spritebatch batch, float parent alfa) {font.draw (batch, text, x, y); } Public zero set position (float x, float y) {this.x = x; This.y = y; } Public Zero Set Text (String Text) {this.text = text; }  

}

In the screen category:

  @ override public zero show (batch = new sprintbatch); Platform = new stage (Gdx.graphics.getWidth (), Gdx.graphics.getHeight (), true); Score Text = New Text Acctor ("How To Play: \ n"); ScoreText.setPosition (10, ((Gdx.graphics.getHeight () / 7) * 7)); Stage.addActor (scoreText); }  

In one of my projects I have different fonts for these different phones Size is used:

  // create font float density = gdx. Graphics.jpg (); String path = "hdpi"; If (density & lt; = 1) {path = "mdpi"; } And if (density> 1 & amp; amp; density <1.5f) {path = "hdpi"; } And if (density> = 1.5 & amp; amp; density <2) {path = "xdpi"; } And if (density> = 2) {path = "xxdpi"; } Normal font = New bitmap font (Gdx.files.internal ("font /" + path + "/ fonts.fault"));  

As you can see that I have used bitmapfonts, you can find a bitmapfont maker here, together you can create different size bitmapfonts. In this way you can work with fonts such as you work with bitmaps of your size, and you can also resize the font:

  normalFont.setScale (2.0f) ;  

I hope it helps.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -