cocoscreator 디지털 성장 애니메이션

7442 단어 cocos
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)
    }
},  

좋은 웹페이지 즐겨찾기