TipSystem.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const { ccclass, property } = cc._decorator;
  2. @ccclass
  3. /**
  4. * 提示管理类
  5. * @author 邹勇
  6. */
  7. export default class TipSystem extends cc.Component {
  8. @property({ type: cc.Integer, displayName: "飘动时间" })
  9. tween_time: number = 1;
  10. @property({ type: cc.Integer, displayName: "开始坐标x" })
  11. src_x: number = 0;
  12. @property({ type: cc.Integer, displayName: "开始坐标y" })
  13. src_y: number = 0;
  14. @property({ type: cc.Integer, displayName: "目标坐标x" })
  15. tar_x: number = 0;
  16. @property({ type: cc.Integer, displayName: "目标坐标y" })
  17. tar_y: number = 200;
  18. @property({ type: cc.Integer, displayName: "背景透明度" })
  19. bg_opacity: number = 40;
  20. @property({ displayName: "背景颜色" })
  21. bg_color = new cc.Color(200, 200, 200);
  22. @property({ displayName: "文本颜色" })
  23. tip_color = new cc.Color(255, 255, 255);
  24. @property({ type: cc.Integer, displayName: "文本字体" })
  25. tip_size: number = 40;
  26. onLoad() {
  27. mk.tip = this;
  28. }
  29. start() {
  30. }
  31. /**
  32. * 弹出tips
  33. * @param str
  34. * @param type 弹窗类型 0正常中间弹 1弹到最顶上
  35. */
  36. public async pop(str: string, type: number = 0) {
  37. let node = await mk.pool.getPrefab("game/prefab/tips");
  38. let node_bg = node.getChildByName("bg");
  39. let node_lbl = node.getChildByName("lbl");
  40. let lbl = node_lbl.getComponent(cc.Label);
  41. // node_bg.color = this.bg_color;
  42. // node_bg.opacity = this.bg_opacity;
  43. // node_lbl.color = this.tip_color;
  44. lbl.fontSize = this.tip_size;
  45. lbl.string = str;
  46. node_bg.width = node_lbl.width + 20 < 200 ? 200 : node_lbl.width + 20;
  47. node.width = node_bg.width;
  48. node_bg.height = node_lbl.height + 2;
  49. node.parent = this.node;
  50. node.x = this.src_x;
  51. node.y = this.src_y;
  52. if (type == 0) {
  53. cc.tween(node)
  54. .to(this.tween_time, { x: this.tar_x, y: this.tar_y })
  55. .call(() => {
  56. mk.pool.return("tips", node);
  57. }, this)
  58. .start();
  59. }
  60. else {
  61. this.tween_time = 1;
  62. node.y = 400;
  63. this.tar_y = 520;
  64. cc.tween(node)
  65. .to(this.tween_time, { x: this.tar_x, y: this.tar_y })
  66. .delay(2)
  67. .call(() => {
  68. mk.pool.return("tips", node);
  69. }, this)
  70. .start();
  71. }
  72. }
  73. }