| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- const { ccclass, property } = cc._decorator;
- /**
- * 位图文本
- * @author 袁浩
- */
- @ccclass
- export class BitmapFontC extends cc.Component {
- @property({ tooltip: "字符集配置", type: [cc.SpriteFrame], serializable: true })
- public dataList: cc.SpriteFrame[] = [];
- @property({ visible: false })
- private _string: string = '';
- @property({ tooltip: "文本内容字符串", serializable: true })
- public get string(): string {
- return this._string;
- }
- public set string(value: string) {
- this._string = value + "";
- for (let i = 0; i < this.string.length; i++) {
- let child = this.node.children[i];
- const chair = this.string[i];
- let data = this.getData(chair);
- if (data) {
- if (child) {
- child.active = true;
- child.getComponent(cc.Sprite).spriteFrame = data;
- }
- else {
- let node = new cc.Node(chair)
- let sprite = node.addComponent(cc.Sprite);
- sprite.spriteFrame = data;
- node.parent = this.node;
- }
- }
- else {
- console.error(`BitmapFont中缺少字符 ${chair} 的配置。`)
- }
- }
- for (let i = this.string.length; i < this.node.children.length; i++) {
- const child = this.node.children[i];
- child.active = false;
- }
- }
- private getData(chair: string) {
- for (let j = 0; j < this.dataList.length; j++) {
- const data = this.dataList[j];
- if (data.name == chair) {
- return data;
- }
- }
- return null;
- }
- start() {
- }
- }
|