UIFlyEft.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { Prop } from "../data/Define";
  2. import UIBase from "../fgui/core/UIBase";
  3. import ui_UIFlyEft from "../fgui/res/game/ui_UIFlyEft";
  4. import { xGame } from "../xGame";
  5. export default class UIFlyEft extends UIBase {
  6. public ui: ui_UIFlyEft;
  7. iconPos: Array<any>;
  8. max: number = 8;
  9. delay: number = 0;
  10. public constructor() {
  11. super();
  12. }
  13. protected onConstructor(): void {
  14. this.ui = ui_UIFlyEft.createInstance();
  15. this.contentPane = this.ui;
  16. this.isEject = false;
  17. this.isMuti = true;
  18. this.ui.x += xGame.common.sysOffestNum;
  19. }
  20. getArrPos() {
  21. if (this.iconPos && this.iconPos.length > 0) return;
  22. this.iconPos = [];
  23. let temp;
  24. for (let index = 0; index < this.max; index++) {
  25. temp = this.ui["n" + index];
  26. this.iconPos.push([temp.x, temp.y]);
  27. }
  28. }
  29. show(stPos, edPos, num, type, callback) {
  30. super.show();
  31. //
  32. this.parent.setChildIndex(this, this.parent.numChildren - 1);
  33. //
  34. this.getArrPos();
  35. //初始化img
  36. this.updateUI(type);
  37. //初始化位置
  38. this.updatePos();
  39. //飞行特效
  40. this.runFly(edPos, callback);
  41. //文字特效
  42. this.runWorlds(stPos, num);
  43. }
  44. updateUI(type) {
  45. let temp;
  46. let str;
  47. for (let index = 0; index < this.max; index++) {
  48. temp = this.ui["n" + index];
  49. str = this.getIconStr(type);
  50. temp.url = xGame.common.getGameIconUrl(str);
  51. }
  52. }
  53. getIconStr(type) {
  54. switch (type) {
  55. case Prop.diamond:
  56. return "ty_zs";
  57. case Prop.coin:
  58. return "ty_jb";
  59. default:
  60. break;
  61. }
  62. }
  63. updatePos() {
  64. let temp;
  65. for (let index = 0; index < this.max; index++) {
  66. temp = this.ui["n" + index];
  67. temp.x = this.iconPos[index][0];
  68. temp.y = this.iconPos[index][1];
  69. }
  70. }
  71. runFly(endPos, callback) {
  72. let all = 0;
  73. let temp;
  74. for (let index = 0; index < this.max; index++) {
  75. temp = this.ui["n" + index];
  76. temp.visible = true;
  77. Laya.Tween.to(temp, { x: endPos.x, y: endPos.y }, 600, Laya.Ease.cubicInOut, Laya.Handler.create(this, () => {
  78. temp.visible = false;
  79. all++;
  80. if (all >= this.max) {
  81. callback && callback();
  82. }
  83. }), 20 * index);
  84. }
  85. }
  86. runWorlds(stPos, num) {
  87. let str = "+" + num;
  88. this.ui.txt.text = str;
  89. //
  90. let starX = stPos.x;
  91. let starY = stPos.y + 50;
  92. this.ui.txt.x = starX
  93. this.ui.txt.y = starY
  94. this.ui.txt.visible = true;
  95. this.ui.txt.alpha = 1;
  96. Laya.Tween.to(this.ui.txt, { x: starX, y: starY - 30 }, 500, null, Laya.Handler.create(this, () => {
  97. Laya.Tween.to(this.ui.txt, { alpha: 0 }, 500, null, Laya.Handler.create(this, () => {
  98. this.ui.txt.visible = false;
  99. this.hide();
  100. }))
  101. }))
  102. }
  103. }
  104. UIFlyEft.uiName = "UIFlyEft"