Laya_TS 鼠标点击事件

/**
* name 延时调用
*/
module laya{
	import Sprite = Laya.Sprite;
	import Stage = Laya.Stage;
	import Event = Laya.Event;
	import Browser =Laya.Browser;
	import WebGL = Laya.WebGL;

	export class Timer_DelayExcute{
		private button1: Sprite;
		private button2: Sprite;

		constructor(){
			Laya.init(Browser.clientWidth,Browser.clientHeight,WebGL);

			Laya.stage.alignV = Stage.ALIGN_MIDDLE;
			Laya.stage.alignH = Stage.ALIGN_CENTER;

			Laya.stage.scaleMode = Stage.SCALE_SHOWALL;
			Laya.stage.bgColor = "#232628";

			this.setup();
		}
		private setup():void{
			var vGap:number = 100;

			this.button1 = this.createButton("点我,3s");

			this.button1.x = (Laya.stage.width - this.button1.width)/2;

			this.button1.y = (Laya.stage.height - this.button1.height-vGap)/2;	

			Laya.stage.addChild(this.button1);

			this.button1.on(Event.CLICK,this,this.onDecreaseAlpha);
		}

		private createButton(label:string) : Sprite{

			var w:number = 300,h:number =60;

			var button:Sprite = new Sprite();

			button.graphics.drawRect(0,0,w,h,"#ff7f50");

			button.size(w,h);
			//fillText:在画布上绘制文本
			button.graphics.fillText(label,w/2,17,"20px simHei","#ffffff","center");

			return  button;
		}
		private onDecreaseAlpha(e:Event):void{
			//移除点击事件
			this.button1.off(Event.CLICK,this,this.onDecreaseAlpha);

			//延时调用,类似cocos的ScheduleOnce()
			Laya.timer.once(3000,this,this.onComplete);
		}
		private onComplete():void{
			this.button1.alpha-=0.5;
		}
	}
}
new laya.Timer_DelayExcute();

 


版权声明:本文为Fanstasic原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。