kuainiao

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 如果入口是Main.ts的Main类

private textfield: egret.TextField;
private _txInfo:egret.TextField;
private _bgInfo:egret.Shape;
/**
* 创建场景界面
* Create scene interface
*/
protected createGameScene(): void {

/*** 本示例关键代码段开始 ***/
// 创建图片,比如背景图、或者在某个位置显示一种图片
var bird:egret.Bitmap = new egret.Bitmap();
bird.texture = RES.getRes("egret_icon_png");
bird.x = this.stage.stageWidth / 2;
bird.y = this.stage.stageHeight / 2;
this.addChild( bird );
/*** 本示例关键代码段结束 ***/

/// 为定位设置基准点(即锚点)
bird.anchorOffsetX = bird.width / 2;
bird.anchorOffsetY = bird.height / 2;
bird.x = this.stage.stageWidth * .5;
bird.y = this.stage.stageHeight * .5;

/// 提示信息
this._txInfo = new egret.TextField;
this.addChild( this._txInfo );

this._txInfo.size = 28;
this._txInfo.x = 50;
this._txInfo.y = 50;
this._txInfo.textAlign = egret.HorizontalAlign.LEFT;
this._txInfo.textColor = 0x000000;
this._txInfo.type = egret.TextFieldType.DYNAMIC;
this._txInfo.lineSpacing = 6;
this._txInfo.multiline = true;

this._txInfo.text =
"轻触屏幕调整显示对象位置";

this._bgInfo = new egret.Shape;
this.addChildAt( this._bgInfo, this.numChildren - 1 );

this._bgInfo.x = this._txInfo.x;
this._bgInfo.y = this._txInfo.y;
this._bgInfo.graphics.clear();
this._bgInfo.graphics.beginFill( 0xff0000, 0.5 );
this._bgInfo.graphics.drawRect( 0, 0, this._txInfo.width, this._txInfo.height );
this._bgInfo.graphics.endFill();

this.stage.addEventListener( egret.TouchEvent.TOUCH_BEGIN, ( evt:egret.TouchEvent )=>{
bird.x = evt.localX ;
bird.y = evt.localY ;
}, this );

}

 效果图

 

posted on 2018-07-23 17:34  kuainiao  阅读(742)  评论(0编辑  收藏  举报
View Code