首页 > 技术文章 > TypeScript笔记

shirln 2018-06-25 15:29 原文

显示文字:

this.textTips = new egret.TextField;
this.textTips.size = 24;
this.textTips.textAlign = egret.HorizontalAlign.CENTER;
this.textTips.textColor = 0x843900;
this.textTips.x = this.stage.stageWidth / 2 - this.textTips.width / 2;
this.textTips.y = this.stage.stageHeight - 100;
this.addChild(this.textTips);
this.textTips.text = "Hello world";

输入框:

this.textInput = new egret.TextField;
this.textInput.textAlign = egret.HorizontalAlign.CENTER;//水平方向居中
this.textInput.verticalAlign = egret.VerticalAlign.MIDDLE;//垂直方向居中
this.textInput.inputType = egret.TextFieldInputType.PASSWORD;//密码
this.textInput.displayAsPassword=true;//启用密码
this.textInput.size = 50; this.textInput.type = "input"; this.textInput.width = 300; this.textInput.height = 300; this.textInput.border = true; this.textInput.borderColor = 0x000000; this.textInput.textAlign = egret.HorizontalAlign.CENTER; this.textInput.textColor = 0x77787b; this.textInput.text = "请输入你要输入的内容"; this.textInput.x = this.stage.stageWidth / 2 - this.textInput.width / 2; this.textInput.y = 200; this.textInput.touchEnabled = true; this.addChild(this.textInput);

//添加监听事件
 this.textInput.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
      this.textInput.text = ""; //点击输入框的默认值
       this.textInput.textColor = 0x000000;
        }, this);

 APP进入前后台的判断

egret.lifecycle.addLifecycleListener((context) => {
            // custom lifecycle plugin
        })

        egret.lifecycle.onPause = () => {
                console.log("app 进入后台");
                egret.ticker.pause(); // 关闭渲染与心跳
        }

        egret.lifecycle.onResume = () => {
                console.log("app 进入前台");
                egret.ticker.resume(); // 打开渲染与心跳
        }

遮罩(显示mask部分)

      var mask:egret.Rectangle=new egret.Rectangle(0,0,50,50);//显示的区域
      this._shap=new egret.Shape();
      this._shap.graphics.beginFill(0xff0000);
      this._shap.graphics.drawRect( 0,0,100,100);
      this._shap.graphics.endFill();
      this.addChild(this._shap);
      this._shap.mask=mask; //为某个对象设置遮罩    

碰撞检测:

var isHit:boolean=myShap.hitTestPoint(this._pos.x,this._pos.y);//检测myShap对象的x,y位置知否发生了碰撞

 

推荐阅读