32 lines
1.4 KiB
Java
32 lines
1.4 KiB
Java
|
|
package uno.mloluyu.util;
|
||
|
|
|
||
|
|
import com.badlogic.gdx.Gdx;
|
||
|
|
import com.badlogic.gdx.graphics.Color;
|
||
|
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||
|
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||
|
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
|
||
|
|
|
||
|
|
public class Font {
|
||
|
|
public static BitmapFont loadChineseFont() {
|
||
|
|
FreeTypeFontGenerator generator = null;
|
||
|
|
try {
|
||
|
|
generator = new FreeTypeFontGenerator(Gdx.files.internal("FLyouzichati-Regular-2.ttf")); // 你的中文字体路径
|
||
|
|
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
|
||
|
|
parameter.size = 48;
|
||
|
|
parameter.color = Color.WHITE;
|
||
|
|
parameter.borderWidth = 1;
|
||
|
|
parameter.borderColor = Color.DARK_GRAY;
|
||
|
|
parameter.characters = "返回主菜单确认角色选择了角色人游戏加入联机模式 - 等待其他玩家连接...房间创建房间联机设置开始游戏设置联网中国abcdefghijklmnopqrstuvw暂定xyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||
|
|
|
||
|
|
return generator.generateFont(parameter);
|
||
|
|
} catch (Exception e) {
|
||
|
|
Gdx.app.error("Font Error", "加载中文字体失败: " + e.getMessage());
|
||
|
|
return new BitmapFont(); // 回退默认字体
|
||
|
|
} finally {
|
||
|
|
if (generator != null)
|
||
|
|
generator.dispose();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|