most of the LIBGDX documents on the Internet, the use of the version is 0.9X time left, 1.X version of the relatively few. FreeType in 1. X when the use has changed, write a change.
I am using the Libgdx 1.6 version.
First give two portals, you can go to git to see the official wiki.
The Official FreeType notes
Https://github.com/libgdx/libgdx/wiki/Gdx-freetype
Official sample of FreeType
https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/extensions/ Internationalfontstest.java
Here is a comparison of both ends of the code
Version 0.9X
Package com.example.mylibgdxfont03;
Import Com.badlogic.gdx.ApplicationListener;
Import COM.BADLOGIC.GDX.GDX;
Import Com.badlogic.gdx.graphics.Color;
Import com.badlogic.gdx.graphics.GL10;
Import Com.badlogic.gdx.graphics.g2d.BitmapFont;
Import Com.badlogic.gdx.graphics.g2d.SpriteBatch;
Import Com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
Import Com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeBitmapFontData;
public class Mygame implements Applicationlistener {private Bitmapfont font;
Private Freetypefontgenerator generator;
Private Freetypebitmapfontdata Fontdata;
private SpriteBatch batch;
@Override public void Create () {generator = new Freetypefontgenerator (Gdx.files.internal ("Testfont.ttf")); Fontdata = Generator.generatedata (generator. Default_chars + "The evening breeze to the Glory blow scattered, fame and wealth is so shallow." -I'm a fish seeking water.
", false);//You need to write all the words you want to output, as long as you can't have duplicate words. Font = new Bitmapfont (Fontdata, Fontdata.gettexturerEgion (), false);
Font.setcolor (Color.pink);
Batch = new SpriteBatch ();
} @Override public void Dispose () {font.dispose ();
Generator.dispose ();
Batch.dispose ();
} @Override public void render () {Gdx.gl.glClearColor (1, 1, 1, 1);
Gdx.gl.glClear (Gl10.gl_color_buffer_bit);
Batch.begin (); Font.drawmultiline (Batch, "Hello Everyone: \ n the night breeze blows the splendor away, \ nthe fame is so shallow."
", 50, 220); Font.draw (Batch, "-I am a fish seeking water.
", 150, 90);
Batch.end ();
} @Override public void resize (int width, int. height) {} @Override public void Pause () {} @Override public void Resume () {}} excerpted from http://m.blog.csdn.net/blog/yangyu20121224/9182243
Code for version 1.6
Package com.mygdx.game;
Import Com.badlogic.gdx.ApplicationAdapter;
Import COM.BADLOGIC.GDX.GDX;
Import com.badlogic.gdx.graphics.GL20;
Import Com.badlogic.gdx.graphics.g2d.BitmapFont;
Import Com.badlogic.gdx.graphics.g2d.SpriteBatch;
Import Com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
Import Com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
public class Mygdxgame extends Applicationadapter {spritebatch batch;
Freetypefontgenerator Generator;
Freetypefontparameter parameter;
Private Bitmapfont font;
@Override public void Create () {batch = new SpriteBatch (); Generator = new Freetypefontgenerator (Gdx.files.internal ("Simkai").
TTF "));
parameter = new Freetypefontparameter (); Parameter.characters = "It's very nice and sunny today."
";
Font = generator.generatefont (parameter);
Generator.dispose ();
} @Override public void render () {Gdx.gl.glClearColor (0, 0, 0, 0); Gdx.gl.glClear (Gl20.gl_color_buffer_bit);
Batch.begin (); Font.draw (Batch, "The weather is fine today, it's sunny."
", 100, 100);
Batch.end ();
} @Override public void Dispose () {batch.dispose ();
Super.dispose ();
}
}
The difference is:
1. Generate FreeType
0.9X version of the code
Generator.generatedata (generator. Default_chars
+ "The evening breeze to the Glory blow scattered, fame and wealth is so shallow." -I'm a fish seeking water. ", false);//You need to write all the words you want to output, as long as you can't have duplicate words.
Version 1.6 requires the use of the Freetypefontparameter object
Generator = new Freetypefontgenerator (Gdx.files.internal ("Simkai"). TTF "));
parameter = new Freetypefontparameter ();
Parameter.characters = "It's very nice and sunny today." ";
2. Using Bitmapfont
0.9X Version Code
Font = new Bitmapfont (Fontdata, Fontdata.gettextureregion (), false);
1.6 Version Code
Font = generator.generatefont (parameter);
The freetype differences between version 1.6 and 0.9X are summarized in this article.
Also attach the default parameters of Freetypefontparameter in FreeType
/** the size in pixels */public int size = 16;
/** Foreground Color (required for non-black borders) */Public color color = color.white;
/** Border width in pixels, 0 to disable */public float borderWidth = 0; /** Border color;
Only used if borderWidth > 0 */public Color bordercolor = Color.Black;
/** true for Straight (mitered), False for rounded borders */public Boolean borderstraight = false;
/** Offset of Text shadow on X axis in pixels, 0 to disable */public int shadowoffsetx = 0;
/** Offset of Text shadow on Y axis in pixels, 0 to disable */public int shadowoffsety = 0; /** Shadow color;
Only used if Shadowoffset > 0 */public Color Shadowcolor = new color (0, 0, 0, 0.75f);
/** the characters the font should contain */public String characters = Default_chars;
/** Whether The font should include kerning */public Boolean kerning = true;
/** the optional Pixmappacker to use */public pixmappacker packer = null; /** Whether to flip the font vertically */public BooleanFlip = false;
/** Whether or not to generate MIP maps for the resulting texture */public Boolean genmipmaps = false;
/** minification Filter */public texturefilter minfilter = texturefilter.nearest; /** magnification filter */public texturefilter magfilter = texturefilter.nearest;