2025-09-23 21:46:12 +08:00
|
|
|
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;
|
2025-09-27 15:02:52 +08:00
|
|
|
parameter.characters = "返回主菜单确退出认角色选择了角色人游戏加入联机模式 - 等待其他玩家连接...房间创建房间联机设置开始游戏设置联网中国重新开始胜者游戏结束返回主界面abcdefghijklmnopqrstuvw暂定xyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
2025-09-23 21:46:12 +08:00
|
|
|
|
|
|
|
|
return generator.generateFont(parameter);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Gdx.app.error("Font Error", "加载中文字体失败: " + e.getMessage());
|
|
|
|
|
return new BitmapFont(); // 回退默认字体
|
|
|
|
|
} finally {
|
|
|
|
|
if (generator != null)
|
|
|
|
|
generator.dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|