Msg.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { cocosz } from "./CocosZ";
  2. export default class Msg {
  3. private static isShow: boolean = false;
  4. private static isTouch: boolean = false;
  5. public static tipList: Array<cc.Node> = [];
  6. public static Show(msg: string, group?: string) {
  7. let pre = cocosz.resMgr.getRes("TipsPanel", cc.Prefab);
  8. if (pre) {
  9. let node: cc.Node = cc.instantiate(pre);
  10. // if (group) node.group = group;
  11. node.group = 'ui';
  12. if (node) {
  13. node.position = cc.v3(cc.winSize.width / 2, cc.winSize.height / 2 + 300);
  14. cc.director.getScene().addChild(node, 10000);
  15. let label: cc.Label = cc.find("label", node).getComponent(cc.Label);
  16. label.string = msg;
  17. node.scale = 0;
  18. let tween = cc.tween(node);
  19. tween.to(0.25, { scale: 1 }, { easing: "backOut" });
  20. tween.delay(2)
  21. tween.to(0.25, { scale: 0 }, { easing: "backIn" });
  22. tween.call(() => { node.destroy(); });
  23. tween.start();
  24. for (let i = Msg.tipList.length - 1; i >= 0; i--) {
  25. if (Msg.tipList[i].isValid) {
  26. Msg.tipList[i].y += 120;
  27. }
  28. else {
  29. Msg.tipList.splice(i, 1);
  30. }
  31. }
  32. Msg.tipList.push(node);
  33. }
  34. } else {
  35. cc.log("提示面板显示失败!");
  36. }
  37. }
  38. }