LIBGDX Development Tutorial (v)--use of beautiful fonts

Source: Internet
Author: User
Tags libgdx

http://blog.sina.com.cn/s/blog_dbc528b10101hppg.htmldo Android Open classmate often tangled how can use some beautiful font to get user's heart, if you want to achieve this goal, then TTF font is essential. What is a TTF font? There may be many unfamiliar with the TTF fontClassmate a look so unfamiliar name is frightened, do not worry, in fact he is not terrible. The so-called TTF is actually a format, just like this, like " 123.ttfand 123.txt"Is the same, the". txt "document is a saved text, and TTF is the same as the". Fnt "file that Hiero generates. But Chinese commonly used 3500 words, you can not use Hiero to do it yourself, how to do it? In fact, Microsoft has long solved this problem, it provides us with this TTF font, save Chinese characters, convenient for us to use. LIBGDX Game engine (1 groups): 187378034 LIBGDX Game engine (2 groups): 148848483 LIBGDX Game engine (3 group): 79168470
LIBGDX Domestic Exchange forum :
www.libgdx.net   1. You don't know the F Reetype!  people may wonder why potatoes Use this title, if the packaged class I can't find. I'm sorry, the API you can not find this class, because he is an additional extension of the package, if you build the project through Step-ui, the default is not to join this package, if we want to use, we need to manually import, the following potatoes to introduce you to the introduction of the method.   (1) Open the unpacked 0.9.8 version of the package, find the inside of the Extensions folder, open, enter the Gdx-freetype folder below, find Gdx-freetype.jar and Gdx-freetype-natives.jar.     (2) Expansion pack Import  First of all Core CodeProject, will Gdx-freetype.jarCopy and Paste to Core CodeThe project's Lib folder, and then add it to the referenced Libraries library. Secondly Android ProjectWill Gdx-freetype.jarCopy and Paste to -androidThe project's Lib folder, and then add it to the referenced Libraries library. At last Desktop ItemsWill Gdx-freetype-natives.jarCopy, Paste to -desktopProject in the Lib folder, and then add it to referenced libraries.   ( the steps are as follows, because the join method is the same, here I just put a picture )  

  (3)Will Gdx-freetypefolder, ArmeabiAnd armeabi-v7aTwo folders are copied to the-android project, replacing the original Armeabi and armeabi-v7a folders.   Comparison chart:


PS:Perhaps people will wonder what this libgdx.so file is, and why Android devices can run the. ttf file? And without him it's been an error? Here's a simple explanation of what the. so file is going to be. Answer: In General, the. So file is often said to be a dynamic link library, compiled from C or C + +,The library is loaded by the Android operating system program when the executable file is loaded or run. As part of the loading process, it is responsible forResolving external references(such as libraries). On different systems, the executable file contains a table called Import directory, and each item of the table contains the name of a library. Depending on the name of the record in the table, the library that the program needs is loaded, then it loads into memory, then updates the executable program based on the address of the library that is determined after the library is loaded, updates the function in the library, or references the data in the library. This is the principle function of the. so file.
2.FreeTypeFontGenerator class   API definition:TTF font generator (producer)------ because this class is not written in the API, actually FreetypefontgeneratorAnd Texture is the same, all just a container, responsible for the ". TTF" file and then spare.   Functional Use:Responsible for saving and parsing the ". TTF" format file.  --------  this is the same as the Texture class.     How to use:Freetypefontgenerator are generally used in conjunction with Freetypebitmapfontdata. Such as:
PS: Here is a special statement, if you are using the above potato to download the TTF font file, you must change the file name to "English name. TTF", compared to the potato use is " Chinese doll body." TTF"will need to rename it to"Baby.ttf", this is because LIBGDX read the file does not support the Chinese file name , so do not take it, otherwise this error should not be.   3. Freetypebitmapfontdata class   API Definition: responsible for handlingFreetypebitmapfontdata of data (processors)------This class is not written in the API .   Functional Use:Responsible for processing freetypegenerator data-----------and theBitmapfontdata Similar  How to use:Freetypebitmapfontdata fontdata = freetypegenerator.generatedata (int Size, some Chinese String, false);Here I briefly introduce the above class of several parameters and important member variables, the first is the size of the font, the second is the Chinese string (that is, the Chinese character, need to quote), the third flip state.  Freetypebitmapfontdata has an important member variable default_chars , which is the author Mario gives us a packaged basic English character open Freetypebitmapfontdata You will see variables such as the assignment, so that even ". TTF "There are no English characters in the font, we can also output English characters, because the author has already packed us."



4. A simple example   Here the potatoes simply wrote an example, to give you a demonstration, examples are relatively simple, the basic one to understand, it is estimated that we can learn.   PS: about Key with Name ' * * * * is the cause of the already in map error, and It is also common for everyone to encounter this problem, he is due to Freetypegenerator.generatedata (int Size, some Chinese string, false), medium "Some Chinese string" parameter does not allow duplicate characters to appear, For example, this sentence " long handsome people confession is called Confession" in the " confession " 2 words appeared 2 times, this is not allowed, Generatedata is not allowed to repeat the same character loading, I hope everyone attention.  The code is as follows:Package Com.potato;

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.OrthographicCamera;
Import Com.badlogic.gdx.graphics.Texture;
Import Com.badlogic.gdx.graphics.Texture.TextureFilter;
Import Com.badlogic.gdx.graphics.g2d.BitmapFont;
Import Com.badlogic.gdx.graphics.g2d.Sprite;
Import Com.badlogic.gdx.graphics.g2d.SpriteBatch;
Import com.badlogic.gdx.graphics.g2d.TextureRegion;
Import Com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
Import Com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeBitmapFontData;
Import Com.badlogic.gdx.graphics.g2d.tiled.TileAtlas;
Import Com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer;
Import Com.badlogic.gdx.graphics.g2d.tiled.TiledLoader;
Import Com.badlogic.gdx.graphics.g2d.tiled.TiledMap;

public class Map implements Applicationlistener {
Private Bitmapfont Font;

Private Freetypefontgenerator Generator;

Freetypebitmapfontdata Fontdata;

private SpriteBatch batch;

@Override
public void Create () {
Generator = new Freetypefontgenerator (
Gdx.files.internal ("Data/baby.ttf"));

Fontdata = Generator.generatedata (generator.default_chars
+ "Long handsome people confess to call, ugly man that sexual harassment." Struggle little potatoes mobile phone work game room ", 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.red);

Batch = new SpriteBatch ();

}

@Override
public void 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 fighting Potato: \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \") ", 50, 220);
Font.draw (Batch, "--------Var3d mobile Phone working game room", 150, 90);

Batch.end ();
}

@Override
public void Resize (int width, int height) {
}

@Override
public void Pause () {
}

@Override
public void Resume () {
}
Effect( var3d cell phone work game room This is not a potato studio, is the Exchange group inside a friend's ID, but this sentence is really he said. 5. About being sprayedRecently some friends who have seen the potato blog have given the potatoes some good feedback and help, here together thanks, you let the potatoes feel that the world is still more normal. But there are always some wonderful, there is a QQ called " the fish that Miss you"2 goods, directly add my QQ scold me, the first sentence with the parents scold, and then said to write the garbage, and then said no technical content, are perfunctory examples. I want to say that I write a blog just out of help to learn libgdx friends, and Just for Beginners, just to provide communication, you think I write rubbish, then you can write, just like Cat TotalSaid, " begging is too much money.”。 If you have the opinion can communicate with me, mention my parents do what, you say example superficial, I don't believe you just learn libgdx when come up first to a box2d then directly iOS development, some basic examples of difficult to write, beginners How to understand, originally new knowledge is not very good to accept, examples difficult is more difficult to learn, Each example potatoes are written by simple knowledge to explain new knowledge, unrelated to other, and attached to the text is to let everyone understand. Potatoes to write a tutorial, a large part of the reason is that when the potato learned libgdx when there is no decent tutorial, are from the official tests and demo look over, the hardship is self-evident, at that time I would particularly like to have a simple tutorial, only the method to achieve, while example code can run up, So I was interested in learning, but there was no, then night bright Lone Star lightThe seniors out of the tutorial gave a lot of help to the potatoes, so potatoes have always wanted to write a blog also to do such a good thing. and group of friends chatted, we all hope to have a new version (0.9.8) of the tutorial, after all, the new version changed a lot of things, before a lot of interfaces are discarded, many ways to implement all changed, so the potato decided to smoke 2 hours a day to write blog. Here, I would like to say to everyone, the potato blog only for beginners and libgdx beginners to see, if you are high-tech, please ignore yourself, you don't have to pay for potatoes, you see?, although be sprayed, but please believe, as a boy from the Northeast, my heart is quite big,I 'm going to keep writing., just like in the group Brother Var3dSaid, "you're not a renminbi, you can't be loved by everyone.”。 Thank you for supporting my friends in the group: Var3d, cat total, small z, radish, rookie, Shadow, Xu Giuxian, Chengdu-315 great gods, etc.Friend's support, is that you tell potatoes, this world is still more normal, 2B less.

TTF font: http://www.cr173.com/soft/36990.html   TTF Font Detailed description address: http://baike.baidu.com/view/1361555.htm   data address: http://www.badlogicgames.com/wordpress/?p=2300 Source Download:http://pan.baidu.com/s/1EGkt2Written in the end, there's aboutthe the use of beautiful fontsThe basic method is introduced here today, the next one is about the LIBGDX framework "Animation class animation"I'll introduce you to the blog. Use of animation。 If you have any questions can add me QQ: 316344618and discuss it together. PS: Today written relatively late, has been 3.00 in the early morning, I hope that we can give more guidance to help modify the perfect.

LIBGDX Development Tutorial (v)--use of beautiful fonts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.