showPollMoney(num) {//默认状态,一般在onload()调用 this.poolMoney.string = num;//poolMoney是要动态显示的label, var len = this.poolMoney.string.length if (len < 14) { var str = this.poolMoney.string for (var i = 0; i < 14 - len; i++) {//默认14位0 str = "0" + str; } } this.poolMoney.string = str; }, //***每次改变值时调用,jackpot是传入的最终值 showJackpot(jackpot) { var str_jackpot = this.poolMoney.string; var cur_jackpot = parseInt(str_jackpot); var interval =10;//根据效果调整累加值 this.jackpotAction = cc.repeatForever(cc.sequence(cc.delayTime(0.01), cc.callFunc(function () { cur_jackpot = cur_jackpot + interval; if (cur_jackpot > jackpot) { cur_jackpot = jackpot; this.poolMoney.node.stopAllActions(); } var str = ""; for (var j = 0; j < 14 - ("" + cur_jackpot).length; ++j) { str = str + "0"; } this.poolMoney.string = str + cur_jackpot; }.bind(this)))); this.poolMoney.node.runAction(this.jackpotAction); }, //比如断线后设置原来的值时调用 setPoolMoney(money) { var times = 20; if (money > 10000) { times = 50; } else if ((money > 1000 && money <= 10000)) { times = 30; } var num = parseInt(this.poolMoney.string); var interval = parseInt(Math.floor(money) / Math.floor(times)); this.poolMoneyAction = cc.repeatForever(cc.sequence(cc.delayTime(0.01), cc.callFunc(function () { num = num + interval; if (num >= money) { num = money this.showPollMoney(num); this.poolMoney.node.stopAllActions(); } this.showPollMoney(num); }.bind(this)))); this.poolMoney.node.runAction(this.poolMoneyAction); },
原文:https://www.cnblogs.com/CC-Right/p/10839989.html