cocoscreator自定义吐司

/ CocosCreator / 没有评论 / 3000浏览
 createTips(str) {
        let spineNode = new cc.Node();
        spineNode.name = 'tipsNode';
        spineNode.setPosition(0, 0);
        // spineNode.parent = this.node;
        spineNode.parent = cc.find("Canvas");
        /*  let sprite = spineNode.addComponent(cc.Sprite);
          sprite.spriteFrame = this.tipsBg;*/
        let ctx = spineNode.addComponent(cc.Graphics);
        ctx.fillColor = new cc.Color().fromHEX('#00000066');
        let width = str.length * 50;
        if (width < 300) {
            width = 300;
        }
        ctx.rect(-(width / 2), -50, width, 100);
        ctx.fill();
        let node = new cc.Node;
        node.parent = spineNode;
        let label = node.addComponent(cc.Label);
        label.string = str;
        spineNode.opacity = 0;
        cc.tween(spineNode).by(0.5, {opacity: 255}).delay(0.5).to(0.5, {y: 50, opacity: 0}).call(() => {
            console.log("完事")
            spineNode.removeFromParent(true);
        }).start();
        /*   spineNode.runAction(cc.sequence(cc.fadeIn(0.1), cc.delayTime(0.5), cc.spawn(cc.moveBy(0.5, 0, 50), cc.fadeOut(0.5)), cc.callFunc(() => {
               spineNode.removeFromParent(true)
           })));*/

    },