| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- // Learn cc.Class:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
- cc.Class({
- extends: cc.Component,
- properties: {
- // foo: {
- // // ATTRIBUTES:
- // default: null, // The default value will be used only when the component attaching
- // // to a node for the first time
- // type: cc.SpriteFrame, // optional, default is typeof default
- // serializable: true, // optional, default is true
- // },
- // bar: {
- // get () {
- // return this._bar;
- // },
- // set (value) {
- // this._bar = value;
- // }
- // },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.timeMax = 50;
- // this._init();
- timer = this;
- },
- //设置时间 并且开始
- setTimeInit(timeMax){
- this.timeMax = timeMax;
- this._init();
- },
- //增加 或者减少
- setTime(time){
- this.timer += time;
- },
- //开始倒计时 使用 timeMax 作为 倒计时的时间
- _init(){
- this.tag = false;
- this.timer = this.timeMax;
- this.t = 1;
- let self = this;
- this.slider = UtilsNode.getNode("Slider",this.node)
- this.time = UtilsNode.getNode("time",this.node)
- this.Alarmclock = UtilsNode.getNode("Alarmclock",this.time)
- this.t = UtilsNode.getNode("t",this.Alarmclock)
- this.mySlider = this.slider.getComponent("mySlider")
- this.timec = this.time.getComponent("time");
- this.mySlider.setCallBack(function (event) {
- var slider = event;
- // //do whatever you want with the slider
- //
- console.log("Slider3的回调函数",slider.progress);
- self.timec.setProgressBar(slider.progress);
- });
- this.sliderc =this.slider.getComponent(cc.Slider);
- },
- setTimeEndCallBack(timeEndCallBack){
- this.timeEndCallBack = timeEndCallBack;
- },
- timeEndCallBack(){},
- setTimeUpdateCallBack(timeUpdateCallBack){
- this.timeUpdateCallBack = timeUpdateCallBack;
- },
- timeUpdateCallBack(){},
- update (dt) {
- if (this.timer > 0) {
- this.timer-=dt;
- let tt = this.timer/this.timeMax;
- //设置倒计时的进度条
- this.timec.setProgressBar(tt);
- if (Math.floor(parseInt(this.timer)) < 10) {
- this.t.color = new cc.color(255,0,0,255)
- }
- this.t.getComponent(cc.Label).string = Math.floor(parseInt(this.timer))+"";
- if (this.timeUpdateCallBack!=null) {
- this.timeUpdateCallBack(this.timer);
- }
- }else{
- if (this.timec) {
- this.timec.setProgressBar(0);
- }
- if (this.timeEndCallBack != null) {
- this.timeEndCallBack();
- }
- }
- },
- });
|