| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- cc.Class({
- extends: cc.Component,
- properties: {
-
- },
- onLoad () {
- this.TimeLabel = this.node.getComponent(cc.Label);
- //init
- this.Init();
- },
- Init()
- {
- this.curtTime = {'second':0,'millisecond':0,'secondBase':60,'millisecondBase':60};
- },
- InitTime(time)
- {
- this.TimeLabel.string = this.ShowTime(time);
- this.curtTime.second = time.second;
- this.curtTime.millisecond = time.millisecond;
- },
- CountDown(callback)
- {
- let times = this.curtTime.second*this.curtTime.millisecondBase + this.curtTime.millisecond;
- times--;
-
- this.schedule(function(){
- this.TimeMinus();
- this.TimeLabel.string = this.ShowTime(this.curtTime);
- if(this.curtTime.second*this.curtTime.millisecondBase + this.curtTime.millisecond == 0)
- {
- callback();
- }
- }.bind(this),0.01,times);
- },
- TimeMinus()
- {
- if((this.curtTime.millisecond-1) < 0)
- {
- this.curtTime.millisecond = this.curtTime.millisecondBase-1;
- this.curtTime.second--;
- return;
- }
- this.curtTime.millisecond--;
- },
- ShowTime(time)
- {
- let second = '';
- let millisecond = '';
- if(time.second<10)
- {
- second ='0'+time.second;
- }
- else
- {
- second = time.second;
- }
- if(time.millisecond<10)
- {
- millisecond = '0' + time.millisecond;
- }
- else
- {
- millisecond = time.millisecond;
- }
- return second+':'+millisecond;
- }
- });
|