123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- const Global = require("Global");
- var SoundFun = require("CachetaSoundFun");
- cc.Class({
- extends: cc.Component,
- properties: {
-
- _countdown:0,
- _totalTime:0,
- },
- onLoad: function()
- {
- this.node.getChildByName("TimeSprite").getComponent(cc.Sprite).fillRange = 1
- this.node.active = false;
- },
- getNowTimeColor(times) {
- if(times <= 6) {
- return new cc.color(255, 30, 0);
- }else if(times <= 9) {
- return new cc.color(255, 144, 0);
- }else if(times <= 12) {
- return new cc.color(230, 255, 0);
- }else{
- return new cc.color(0, 255, 31);
- }
- },
- stopTimeSchedule: function(show)
- {
- // var SystemLeftTimeLabel = this.node.getChildByName("TimeLabelNode").getChildByName("SystemTimeLabel").getComponent(cc.Label);
- // SystemLeftTimeLabel.string = 0;//系统时间
- // var UserLeftTimeLabel = this.node.getChildByName("TimeLabelNode").getChildByName("UserTimeLabel").getComponent(cc.Label);
- // UserLeftTimeLabel.string = 0;//玩家时间
- if (this.timeCallback != null)
- {
- this.unschedule(this.timeCallback);
- this.timeCallback = null;
- }
- if(show){
- this.node.active = true;
- }else{
- this.node.active = false;
- }
- },
- playTimeAction: function(SystemLeftTime,UserLeftTime, bSelf)
- {
- this.node.active = true;
-
- this._usedUserTime = false;
- this._countdown = UserLeftTime.toFixed(1);
- this._waitTime = 0;
- this._totalTime = SystemLeftTime;
- // var UserLeftTimeLabel = this.node.getChildByName("TimeLabelNode").getChildByName("UserTimeLabel").getComponent(cc.Label);
- // UserLeftTimeLabel.string = Math.floor(UserLeftTime).toString();//玩家时间
- let aniNode = this.node.getChildByName("ani");
- aniNode.angle = UserLeftTime/SystemLeftTime*360;
- let spNode = this.node.getChildByName("TimeSprite");
- spNode.color = this.getNowTimeColor(this._countdown);
- var self = this
- this.timeCallback = function()
- {
- self._waitTime = self._waitTime+0.1;
- if(self._countdown <= 0){
- self.stopTimeSchedule(true);
- return;
- }
- self._countdown = self._countdown-0.1;
- if(self._countdown < 0){
- self._countdown = 0;
- }
- spNode.color = self.getNowTimeColor(self._countdown);
- aniNode.angle = self._countdown/SystemLeftTime*360;
- if(Math.abs(self._countdown - 5.5) <= 1e-7 && bSelf) {
- Global.print("bofang5")
- SoundFun.playEffectEX("time");
- }
- if(Math.abs(self._countdown - 3.5) <= 1e-7 && bSelf) {
- Global.print("bofang3")
- SoundFun.playEffectEX("time");
- }
- if(Math.abs(self._countdown - 1.5) <= 1e-7 && bSelf) {
- Global.print("bofang1")
- SoundFun.playEffectEX("time");
- }
- // if(!self._usedUserTime){//还没有使用玩家时间
- // SystemLeftTimeLabel.string = parseInt(self._countdown);
- // self._totalTime = 30;
- // }else{//已经开始使用玩家时间
- // SystemLeftTimeLabel.string = parseInt(self._countdown);
-
- // self._totalTime = 30;
- // }
- // UserLeftTimeLabel.string = parseInt(self._countdown);
- if(self._countdown/self._totalTime >= 0){
- self.node.getChildByName("TimeSprite").getComponent(cc.Sprite).fillRange = self._countdown/self._totalTime;
- }
- }
- this.unschedule(this.timeCallback);
- this.schedule(this.timeCallback,0.1);
- },
- start () {
-
- },
-
- });
|