cocoscreator 보상 애니메이션

11565 단어 cocos
cc.Class({
    extends: cc.Component,

    properties: {
        awardItem: cc.Prefab,
        nodeAward: cc.Node,
    },

    showAwardAnim: function (awardList) {
        this.items = [];
        this.nodeAward.y = -200;
        this.nodeAward.removeAllChildren();
        for (let i = 0; i < awardList.length; i++) {
            let item = cc.instantiate(this.awardItem);
            let award = awardList[i];
            var itemName = award .name;
            var itemAmount = award .amount;
            var richMsg = cc.find("richMsg", item).getComponent(cc.RichText);
            var str = "" + " " + "" + itemName + "" + "x" + itemAmount + "";
            richMsg.string = str;
            this.nodeAward.addChild(item);
            this.items.push(item);
        }
        this.node.active = true;
        this.playAnim();
    },

    playAnim: function () {
        var spMoveBy = cc.moveTo(0.5, 0, 0);
        this.nodeAward.runAction(spMoveBy);
        for (let i = 0; i < this.items.length; i++) {
            var item = this.items[i];
            if (item) {
                var distance = this.awardItem.data.height * i + i * 10;
                var action = cc.sequence(
                    cc.delayTime(0.5),
                    cc.moveBy(0.5, 0, distance),
                )
                item.runAction(action);
            }

            if (i == this.items.length - 1) {
                var self = this;
                setTimeout(() => {
                self.node.active = false;
                }, 2000);
            }
        }
    },

});

좋은 웹페이지 즐겨찾기