"Open source Java Game Framework Libgdx theme" -08-Chinese display and drawing

Source: Internet
Author: User
Tags libgdx

Although LIBGDX is an open Source engine written by the American Mario Zechner (ie badlogicgames), because LIBGDX is implemented with OpenGL, LIBGDX is able to support Chinese, and Chinese characters in Libgdx are displayed by means of stickers. Use the Bitmapfont and spritebatch combinations to complete the drawing of the text, the construction of Bitmapfont need a description of the text of the Fnt file, and a text image to provide a PNG file. Therefore, the display of Chinese, in the final analysis, is to read a. fnt file containing Chinese information and the corresponding. png file and show the problem. Use Hiero.jar Note: If you want to use the word, can only be in the. fnt file inside the text, otherwise it is not displayed. For example, I have a "struggle little potatoes" in the file, then I can write these words in the program output, but if I want to output "Du Fu is very busy" the 4 characters, Because there is no such word in the edit file, it is not displayed. PS: Why would you like to load a fnt file? What is the. fnt file for? A: Because LIBGDX is implemented using OpenGL, LIBGDX can support Chinese. But the Chinese characters in Libgdx are displayed by way of stickers, and we open them with Notepad. Potato.fnt file, which shows part of the content (such as), as well as the reference to the. PNG image, you can see clearly that libgdx text drawing is based on the fnt file to obtain the corresponding text in PNG coordinates position, and then take the corresponding part of the picture to draw. 2.BitmapFont Class API Description: Render bitmap fonts, including 2 files: An image file Textureregion, containing symbols in the Anglecodebmfont text format, which describes each glyph as an image file. The text is drawn using a spritebatch. Functional use: render static text, while you can set the text color, text size and so on. How to use: We can manually set the text size and color and rotation, where the use of function settings is possible, in the Hiero can be set, you can choose which method to set, new () False is the management of the rollover. Word wrapping shows that you only need to add a newline character (\ n) to the instance code in Chinese characters:
1  PackageCom.mygdx.drawimage;2 3 ImportCom.badlogic.gdx.ApplicationListener;4 ImportCom.badlogic.gdx.Gdx;5 Importcom.badlogic.gdx.graphics.GL20;6 ImportCom.badlogic.gdx.graphics.g2d.BitmapFont;7 ImportCom.badlogic.gdx.graphics.g2d.SpriteBatch;8 /**9 * Display and draw Chinese charactersTen  * @authorJack (Le Zhi) One * @blog dtblog.cn A * @qq 984137183 -  */ -  Public classUsefontImplementsApplicationlistener { the  -     //elf Batch -     Privatespritebatch Batch; -     //Font +     PrivateBitmapfont font; -      + @Override A      Public voidCreate () { atFont=NewBitmapfont (Gdx.files.internal ("Data/test.fnt"), Gdx.files.internal ("Data/test.png"),false);//loading font files and font pictures -Font.setcolor (0.5f,0.4f,0.6f,1);//Set Color -Batch=NewSpriteBatch (); -     } -  - @Override in      Public voidResizeintWidthintheight) { -         //TODO auto-generated Method Stub to  +     } -  the @Override *      Public voidrender () { $Gdx.gl.glClearColor (1, 1, 1, 1);Panax Notoginseng Gdx.gl.glClear (gl20.gl_color_buffer_bit); - Batch.begin (); theFont.draw (Batch, "I'm big for You", 200, 160);//Drawing Fonts +Font.draw (Batch, "I'm big, you're big", 200, 360);//draw fonts, wrap with escape characters A batch.end (); the     } +  - @Override $      Public voidpause () { $         //TODO auto-generated Method Stub -  -     } the  - @OverrideWuyi      Public voidResume () { the         //TODO auto-generated Method Stub -  Wu     } -  About @Override $      Public voidDispose () { -         //TODO auto-generated Method Stub -  -     } A  +}
Effect: The original written by Bo Master Le Zhi Editor, the copyright belongs to the owner of the Bo. The original address http://www.dtblog.cn/1139.html reprint please specify the source!

"Open source Java Game Framework Libgdx theme" -08-Chinese display and drawing

Related Article

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.