function showTips(tipText, fontSize = 36, showTime = 2e3) {
let arrTips = this._arrTips;
let text;
if (arrTips == null) {
arrTips = [];
let box = new Laya.Box();
Laya.stage.addChild(box);
box.zOrder = this._tipsZOrder;
for (let index = 0; index < 3; index++) {
let tipBox = new Laya.Box();
tipBox.anchorX = tipBox.anchorY = .5;
tipBox.centerX = 0;
let bgBox = new Laya.Box();
bgBox.bgColor = "#000000";
bgBox.width = 800;
bgBox.height = 80;
bgBox.alpha = .7;
tipBox.addChild(bgBox);
text = new Laya.Text();
tipBox.addChild(text);
text.fontSize = fontSize;
text.color = "#FFFFFF";
text.width = 800;
text.height = 50;
text.y = 15;
text.align = "center";
text.valign = "middle";
arrTips.push(text);
box.addChild(tipBox);
tipBox.visible = false;
}
this._arrTips = arrTips;
box.width = 600;
box.centerX = 0;
box.centerY = -100;
}
if (arrTips.length == 0)
return;
text = arrTips.shift();
text.text = tipText;
text.wordWrap = true;
text.color = "#FFFFFF";
let time = showTime;
let tipBox = text.parent;
tipBox.visible = true;
tipBox.scale(.8, .8);
tipBox.alpha = 1;
Laya.Tween.to(tipBox, {
scaleX: 1,
scaleY: 1
}, 200, Laya.Ease.backOut, Laya.Handler.create(this, function (node) {
Laya.timer.once(time - 600, this, function () {
Laya.Tween.to(tipBox, {
alpha: 0
}, 400, null, Laya.Handler.create(this, function () {
node.parent.visible = false;
arrTips.push(node);
}));
});
}, [text]));
}
还有一种是web通用的弹窗
function showTip(str) {
const view = document.createElement("div");
view.id = "tipView";
document.body.appendChild(view);
view.innerHTML = str;
view.style.cssText = "position:absolute;top:30%;left:50%;margin-left:-150px;background:black;width:300px;height:40px;font-size:28px;color:white;opacity:0.8;z-index:999999999;text-align:center;"//位置样式自行调试
setTimeout(() => {
let opacity = 0.7;
var timeId = setInterval(function () {
opacity = opacity - 0.1;
if (opacity <= 0) {
clearInterval(timeId);
view.remove();
}
view.style.opacity = opacity;
}, 30);
}, 400);
}