1.创建文本
/**
*size 文字大小
color 文字颜色
VAgain 文字的垂直对齐方式 居中对齐
HAgain 文字的水平对齐方式 居中对齐
family 文字的样式 默认为 "Verdana"
说明:根据TypeScript的官方文档说明 这里使用的let 而并非var
官方文档提示 尽量减少var的使用而是用let 来做替代
*/
public createTextfield(size:number,color:number=0xffffff,VAgain:string=egret.VerticalAlign.MIDDLE,HAgain:string=egret.HorizontalAlign.CENTER,family: string = "Verdana"):egret.TextField
{
let textfield= new egrte.textField()
textfield.size = size;
textfield.textColor = color;
textfield.textAlign = hAlign;
textfield.verticalAlign = vAlign;
textfield.fontFamily = family;
textfield.cacheAsBitmap = true;
return textfield;
}
//显示文字提示
public showTips(tip:string,color:number=0xffffff):void
{
let maxW:number = this.stage.width;
let maxH:number = this.stage.height;
let textfield: egret.TextField = createTextfield(30);
textfield.text = tip;
textfield.textColor = color;
textfield.width = textfield.textWidth;
textfield.height = textfield.textHeight;
//居中显示
textfield.x = (max_W - textfield.width) * 0.5;
extfield.y = (max_H - textfield.height) * 0.5;
// core.LayerCenter 为游戏场景层
core.LayerCenter.getInstance().stage.addChild(textfield);
//使用egret的自身缓动
// 在缓动结束是清除创建的文本
egret.Tween.get(textfield).to({ y: max_H * 0.4, alpha: 0 }, 1000, egret.Ease.circIn).call(function (target: egret.TextField): void {
target.parent.removeChild(target);
}, this, [textfield]);
}