egret 示例实战六:利用Timer定时器,实现钟表秒针行走效果
Posted wentingc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了egret 示例实战六:利用Timer定时器,实现钟表秒针行走效果相关的知识,希望对你有一定的参考价值。
1.建立一个圆和一根指针形状
1 let circle = new egret.Shape(); 2 circle.graphics.lineStyle(5,0x000000,1,true); 3 circle.graphics.drawCircle(0,0,170); 4 circle.graphics.endFill(); 5 circle.x = Main.instance.stage.stageWidth/2; 6 circle.y = Main.instance.stage.stageHeight/2; 7 this.addChild(circle); 8 9 this.pointer = new egret.Shape(); 10 this.pointer.graphics.beginFill(0xFF9900,1); 11 this.pointer.graphics.drawRect(0,0,160,5); 12 this.pointer.graphics.endFill(); 13 this.pointer.anchorOffsetY = this.pointer.height/2; 14 this.pointer.x = Main.instance.stage.stageWidth/2; 15 this.pointer.y = Main.instance.stage.stageHeight/2; 16 this.addChild(this.pointer);
2.添加Timer计时器,每秒钟走1格,走60格走完一圈
1 this.timer = new egret.Timer(1000,0); this.timer.addEventListener(egret.TimerEvent.TIMER,this.timerFun,this); 2 this.timer.start();
1 private timerFun(){ 2 this.pointer.rotation += 6; 3 // console.log(‘this.pointer.rotation = ‘+this.pointer.rotation); 4 }
3.效果
以上是关于egret 示例实战六:利用Timer定时器,实现钟表秒针行走效果的主要内容,如果未能解决你的问题,请参考以下文章