cocoscreator数字增长动画

cocoscreator缓动动画写法:

updatenNumberAnim: function (curNum) {
    var obj = {};
    obj.num = originNum;
    this.lbNumber.string = obj.num;
    cc.tween(obj).to(1, {num:curNum}, {progress:(start, end, current, t) => {
        this.lbNumber.string = Math.ceil(start + (end - start) * t);
        return start + (end - start) * t;
        }}).start();
},

原生js写法:

updatenNumberAnim: function (curNum) {
    var difference = curNum - originNum;
    var absDifference = Math.abs(difference);
    var changeTimes = absDifference < 8 ? absDifference : 8;
    var changeUnit = absDifference < 8 ? 1 : Math.floor(difference / 8)
    var self = this;
    for (let i = 0; i < changeTimes; i++) {
        (function (i) {
            setTimeout(() => {
                self.lbNumber.string = (originNum += changeUnit)
                if (i == changeTimes - 1) {
                    self.lbNumber.string = curNum;
                }
            }, 100*(i+1));
        })(i)
    }
},  

你可能感兴趣的:(cocos)