美文网首页
cocos creator 3行飘字 渐隐 tips

cocos creator 3行飘字 渐隐 tips

作者: 人气小哥 | 来源:发表于2019-04-16 10:12 被阅读0次
    cc.Class({
        extends: cc.Component,
    
        properties: {
            layerBg: cc.Node,
            labelPfb: cc.Prefab,
        },
    
        // LIFE-CYCLE CALLBACKS:
    
        onLoad () {
            g_tipsMgr = this
        },
    
        start () {
            this.rollNoticeList = []
        },
    
        createShowNode(str) {
            let label = cc.instantiate(this.labelPfb)
            this.layerBg.addChild(label)
    
            this.rollNoticeList.push(label)
            if (this.rollNoticeList.length > 3) {
                let note = this.rollNoticeList.shift()
                // note.removeFromParent(false)
                note.destroy()
            }
    
            let rnum = this.rollNoticeList.length
            let spos = cc.v2(0, 0)
            let idx = 1
            for (let i = rnum - 1; i >= 0; --i) {
                let lb = this.rollNoticeList[i]
                if (i == rnum) {
                    spos = cc.v2(lb.x, lb.y)
                } else {
                    let newy = spos.y + idx * lb.height
                    lb.y = newy
                    idx = idx + 1
                }
            }
    
            label.getComponent(cc.Label).string = str
            
            return label
        },
    
        showRollNotice(str) {
            let label = this.createShowNode(str)
    
            //时间 秒数
            let holdTime = 5
    
             // var callback = cc.callFunc(this.onComplete, this);
            let sequence = cc.sequence(cc.fadeTo(holdTime, 0), cc.callFunc(function(target, score) {
                this.rollNoticeList.shift()
                // target.removeFromParent(false)
                target.destroy()
            }, this))//动作完成后删除
            label.runAction(sequence)
    
        },
    
        // update (dt) {},
    });
    
    

    相关文章

      网友评论

          本文标题:cocos creator 3行飘字 渐隐 tips

          本文链接:https://www.haomeiwen.com/subject/wpyvwqtx.html