const { ccclass, property } = cc._decorator; @ccclass /** * 提示管理类 * @author 邹勇 */ export default class TipSystem extends cc.Component { @property({ type: cc.Integer, displayName: "飘动时间" }) tween_time: number = 1; @property({ type: cc.Integer, displayName: "开始坐标x" }) src_x: number = 0; @property({ type: cc.Integer, displayName: "开始坐标y" }) src_y: number = 0; @property({ type: cc.Integer, displayName: "目标坐标x" }) tar_x: number = 0; @property({ type: cc.Integer, displayName: "目标坐标y" }) tar_y: number = 200; @property({ type: cc.Integer, displayName: "背景透明度" }) bg_opacity: number = 40; @property({ displayName: "背景颜色" }) bg_color = new cc.Color(200, 200, 200); @property({ displayName: "文本颜色" }) tip_color = new cc.Color(255, 255, 255); @property({ type: cc.Integer, displayName: "文本字体" }) tip_size: number = 40; onLoad() { mk.tip = this; } start() { } /** * 弹出tips * @param str * @param type 弹窗类型 0正常中间弹 1弹到最顶上 */ public async pop(str: string, type: number = 0) { let node = await mk.pool.getPrefab("game/prefab/tips"); let node_bg = node.getChildByName("bg"); let node_lbl = node.getChildByName("lbl"); let lbl = node_lbl.getComponent(cc.Label); // node_bg.color = this.bg_color; // node_bg.opacity = this.bg_opacity; // node_lbl.color = this.tip_color; lbl.fontSize = this.tip_size; lbl.string = str; node_bg.width = node_lbl.width + 20 < 200 ? 200 : node_lbl.width + 20; node.width = node_bg.width; node_bg.height = node_lbl.height + 2; node.parent = this.node; node.x = this.src_x; node.y = this.src_y; if (type == 0) { cc.tween(node) .to(this.tween_time, { x: this.tar_x, y: this.tar_y }) .call(() => { mk.pool.return("tips", node); }, this) .start(); } else { this.tween_time = 1; node.y = 400; this.tar_y = 520; cc.tween(node) .to(this.tween_time, { x: this.tar_x, y: this.tar_y }) .delay(2) .call(() => { mk.pool.return("tips", node); }, this) .start(); } } }