Commit ec2255ab authored by Tt's avatar Tt

app

parent 524f2cd2
This diff is collapsed.
This diff is collapsed.
......@@ -1017,6 +1017,53 @@ let pg = {
const id = cc.audioEngine.playEffect(audio.clip, loop);
resolve(id);
})
},
/**
* 显示提示信息
* @param {string} message - 提示信息内容
*/
showToast(message) {
console.log("show toast->" + message);
// 创建一个临时节点显示提示信息
const canvas = cc.director.getScene().getChildByName('Canvas');
if (!canvas) return;
// 创建提示节点
const node = new cc.Node('Toast');
canvas.addChild(node);
node.setPosition(0, 0);
node.zIndex = 999;
// 创建背景
const bg = new cc.Node('ToastBg');
node.addChild(bg);
const bgGraphics = bg.addComponent(cc.Graphics);
bgGraphics.fillColor = cc.Color.BLACK;
bgGraphics.lineWidth = 0;
bgGraphics.roundRect(-200, -30, 400, 60, 10);
bgGraphics.fill();
// 创建文本
const label = new cc.Node('ToastLabel');
node.addChild(label);
const labelComp = label.addComponent(cc.Label);
labelComp.string = message;
labelComp.fontSize = 24;
labelComp.lineHeight = 24;
labelComp.horizontalAlign = cc.Label.HorizontalAlign.CENTER;
labelComp.verticalAlign = cc.Label.VerticalAlign.CENTER;
// 动画显示和消失
node.opacity = 0;
const fadeIn = cc.fadeTo(0.3, 255);
const delay = cc.delayTime(1.5);
const fadeOut = cc.fadeTo(0.3, 0);
const remove = cc.callFunc(() => {
node.removeFromParent(true);
node.destroy();
});
node.runAction(cc.sequence(fadeIn, delay, fadeOut, remove));
}
},
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment