作者:BOSS | 来源:互联网 | 2023-05-18 12:46
一、制作文图字体文件使用TextureMerger制作位图字体,具体查看官方教程。我们这里制作了一组位图字体。二、导入位图字体位图字体素材放入资源配置文件defaul
一、制作文图字体文件
使用TextureMerger制作位图字体,具体查看 官方教程。
我们这里制作了一组位图字体。
![](https://img1.php1.cn/3cd4a/24d65/3b4/059f650849e05328.jpeg)
二、导入位图字体
位图字体素材放入资源配置文件default.res.json
![](https://img1.php1.cn/3cd4a/24d65/3b4/d6059737d1b1b0e1.jpeg)
三、EXML中使用位图字体
拖动一个bitmaplabel组件到exml上
设置右侧属性栏“位图字体”为countdown_fnt
标签为“123”,如下图所示,可正常显示位图字体了
![](https://img1.php1.cn/3cd4a/24d65/3b4/9cc31d76832b6fab.jpeg)
其他:
1. 位图字体文件fnt配置
fnt内保存了图片名,以及各个数字图片的坐标、高宽等信息
![](https://img1.php1.cn/3cd4a/24d65/3b4/da7a4b49c0923e02.jpeg)
2. 位图字体居中
位图字体没有普通Label的居中、居右、居左等设置
![](https://img1.php1.cn/3cd4a/24d65/3b4/3dd62da0892dbb17.jpeg)
如果要位图字体居中,则需要增加一个定位用的Group容器,并将位图字体的width自动扩展,如下图所示:
![](https://img1.php1.cn/3cd4a/24d65/3b4/35bc9cadd154fee9.jpeg)
3. 怎么在代码中创建BitmapLabel?
/**
* 主页场景
* @author chenkai 2018/5/26
*/
class HomeScene extends eui.Component{
private bmFont:eui.BitmapLabel;
public constructor() {
super();
this.skinName = "HomeSceneSkin";
}
protected childrenCreated(){
this.bmFOnt= new eui.BitmapLabel();
this.bmFont.fOnt= "countdown_fnt"; //设置字体配置文件
this.bmFont.text = "123";
this.addChild(this.bmFont);
}
}