[]要做一个方形倒计时,请问该怎么实现,不知道该怎么做

已邀请:

lifereset

赞同来自: laya123

package huamao.layer.ui
{
import app.TheGame;
import laya.display.Sprite;
import laya.maths.Rectangle;
public class CdSprite extends Sprite
{
public static const START:int = -90;
public static const COLOR:String = "#000000";
private var r:Number = BarCell.WID / Math.SQRT2;
private var rect:Rectangle = new Rectangle(0,0,BarCell.WID,BarCell.WID);
private var pos:int = BarCell.WID*0.5;
private var endTime:int;
private var cdTime:int;
public var isCd:Boolean = false;
public function CdSprite()
{
super();
this.scrollRect = rect;
this.alpha = 0.85;
}
public function setSize(bian:int):void{
r = bian / Math.SQRT2;
rect = new Rectangle(0,0,bian,bian);
this.scrollRect = rect;
pos = bian * 0.5;
}
public function set360(value:int):void {
this.graphics.clear();
if(value == -1){
return;
}
this.graphics.drawPie(pos,pos,r,START+(360 - value), 270 , COLOR ,null,0);
}
private function ef():void {
if( TheGame.GetServerTime() > endTime ){
this.stop();
return;
}
var now:int = ( endTime - TheGame.GetServerTime() )/cdTime * 360;
this.set360(now);
}
public function play(time:int,startTime_:int = 0):void
{
this.cdTime = time;
var startTime:int = ( (startTime_ == 0) ?TheGame.GetServerTime() : startTime_ );
this.endTime = startTime + time;
Laya.timer.loop(1,this,ef);
isCd = true;
}
public function stop():void
{
this.set360(-1);
Laya.timer.clear(this,ef);
isCd = false;
}
}
}
 

wudi199553

赞同来自:

计时器属于简单的逻辑操作,你可以使用Laya.timer计时器类去实现,具体实现方案请通过网上查询,有很多实例可供参考!

laya123

赞同来自:

111.png

要回复问题请先

商务合作
商务合作