egret写的tips

本文介绍了如何使用Egret框架创建和显示文本提示。通过`createTextfield`函数创建带有自定义大小、颜色、对齐方式和字体样式的文本字段,并使用`showTips`方法显示文本提示,实现居中显示和缓动效果。同时,文中遵循了TypeScript官方文档的建议,使用`let`代替`var`进行变量声明。
摘要由CSDN通过智能技术生成

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]);

   }







评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值