如何在Libgdx中呈现印地文文本?

如何使用任何字体在Libgdx中呈现印地文文本? 例如,我想渲染单词“प्रकार”

这是我到目前为止:

import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; public class MyGdxGame extends Game { SpriteBatch spriteBatch; BitmapFont font; OrthographicCamera camera; String text, text1; private byte[] myBytes = { (byte) 0xe0, (byte) 0xa4, (byte) 0xa8, (byte) 0xe0, (byte) 0xa4, (byte) 0xbf, (byte) 0xe0, (byte) 0xa4, (byte) 0xb6, (byte) 0xe0, (byte) 0xa5, (byte) 0x89, (byte) 0xe0, (byte) 0xa4, (byte) 0xa4 }; private String myName = new String(myBytes, Charset.forName("UTF-8")); private String hindiStr = "ँंःअआइईउऊऋऎएऐऍऒओऔऑकखगघङचछजझञटठडढणतथदधनऩप" + "फबभमयय़रऱलळऴवशषसहािीुूृॆेैॅॊोौॉ़्।०१२३४५६७८९INV"; @Override public void create() { camera = new OrthographicCamera(); camera.setToOrtho(false, 400, 640); spriteBatch = new SpriteBatch(); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font/mangal.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); // +FreeTypeFontGenerator.DEFAULT_CHARS; The characters the font should contain parameter.characters = hindiStr; parameter.size = 15; font = generator.generateFont(parameter); font.setColor(1.0f, 0.0f, 0.0f, 1.0f); generator.dispose(); text = "शुभ प्रभात"; text1 = "आप का स्वागत है"; } @Override public void render() { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClearColor(1, 1, 0, 1); spriteBatch.setProjectionMatrix(camera.combined); spriteBatch.begin(); font.draw(spriteBatch, "सूक्ष्मजीवों के विभिन्न प्रकार ", 10, 30); font.draw(spriteBatch, myName, 10, 100); spriteBatch.end(); } @Override public void resize(int width, int height) { camera.setToOrtho(false, width, height); } @Override public void dispose() { font.dispose(); spriteBatch.dispose(); } } 

我们可以使用“Chanakya”字体以正确的方式渲染印地文文本。 从hera下载chanyaka.ttf:

http://indiatyping.com/index.php/download/199-chanakya-font

安装字体后。 你应该使用转换器来编码你的印地文文本:

http://indiatyping.com/index.php/font-converter/unicode-to-chanakya-font-converter

一旦转换文本,只需将其复制到您的目的地,你应该很好去。