[LayaAir 2.0]类似古文显示方式脚本,文字垂直显示,可以控制显示速度出现打字效果等

 
/**古文脚本 */
export default class TextAncient extends Laya.Script {
/** @prop {name:text, tips:"显示文本", type:String, default:"hello world"}*/
public text: string = "hello world";
/** @prop {name:color, tips:"字符串类型示例", type:String, default:"#0000ff"}*/
public color: string = "#0000ff";
/** @prop {name:layoutType, tips:"排版方式(verticalRight-0 竖排从右到左)", type:enum, default:0}*/
public layoutType: layoutType = 0;
/** @prop {name:animationState, tips:"动画状态-0 不开启)", type:number, default:0}*/
public animationState: number = 0;
/** @prop {name:animationState, tips:"动画间隔单位毫秒", type:number, default:300}*/
public animationInterval: number = 0;
/** @prop {name:font, tips:"定义字体,比如"Arial, type:number, default:"Arial"}*/
public font: string = "Arial";
/** @prop {name:fontSize, tips:"定义字号,比如20", type:number, default:20}*/
public fontSize: number = 20;

/** @prop {name:verticalSpace, tips:"垂直方向间距", type:number, default:5}*/
public verticalSpace: number = 5;

/** @prop {name:horizontalSpace, tips:"水平方向间距", type:number, default:5}*/
public horizontalSpace: number = 5;

private sprite: Laya.Sprite;
constructor() {
super();
this.sprite = new Laya.Sprite();
}
drawText(x: number, y: number, w: number, h: number) {
console.log(2222);

var j = 0;//控制行列
var printNumber = 0;//当前输出字数
var fonts = this.fontSize + "px" + " " +this.font ;
var xAction = (n) => { return -n * this.fontSize -this.horizontalSpace; };
var yAction = (n) => { return n * this.fontSize + this.verticalSpace; };
this.sprite.pos(x + w-this.fontSize-this.horizontalSpace, 0);
for (let i = 0; i < this.text.length; i++) {
const element = this.text.charAt(i);
var _x = xAction(j);
var _y = yAction(printNumber);
this.sprite.graphics.fillText(element, _x, _y, fonts, this.color, "left");
if (yAction(printNumber + 1) > h) {
j++;
printNumber = 0;
}
else {
printNumber++;
}
}

}
drawTextBySprite(sprite: Laya.Sprite) {
sprite.addChild(this.sprite);
this.drawText(sprite.x, sprite.y, sprite.width, sprite.height);
}
onEnable(): void {

}

onDisable(): void {

}
}
export enum layoutType {
/**竖排 */
verticalRight = 0,
}
已邀请:

要回复问题请先

商务合作
商务合作