showEffect.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { gameMgr } from "./gameMgr";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class NewClass extends cc.Component {
  5. @property()
  6. texMess: cc.Vec4 = new cc.Vec4(0, 0, 0, 0);
  7. @property()
  8. intervalTime: number = 0.05;
  9. @property()
  10. effectType: number = 0;
  11. // LIFE-CYCLE CALLBACKS:
  12. // onLoad () {}
  13. start() {
  14. gameMgr && gameMgr.setMapTs.checkNode(this.node, true);
  15. if (this.node.name.includes("bullet_boom")) {
  16. if (gameMgr.mainCamereRootNode.getBoundingBoxToWorld().intersects(this.node.getBoundingBoxToWorld())) {
  17. gameMgr.shakeEffect(3, 1, true);
  18. }
  19. }
  20. if (this.effectType == 0) {
  21. if (this.getComponent(cc.Sprite) && this.getComponent(cc.Sprite).getMaterial(0).name == "fire") {
  22. let mtl = this.getComponent(cc.Sprite).getMaterial(0);
  23. mtl.setProperty("totalTex", this.texMess);
  24. let num = 1;
  25. this.schedule(() => {
  26. if (!gameMgr.mainCamera.containsNode(this.node)) {
  27. this.node.opacity = 0;
  28. }
  29. else {
  30. this.node.opacity = 255;
  31. }
  32. mtl.setProperty("curTex", num);
  33. num++;
  34. // if (num > this.texMess.x) {
  35. // num = 1;
  36. // }
  37. if (num > this.texMess.x) {
  38. cc.tween(this.node).to(0.2, { opacity: 0 }).call(() => { this.node.destroy() }).start();
  39. }
  40. }, this.intervalTime, this.texMess.x);
  41. } else {
  42. this.node.destroy();
  43. }
  44. }
  45. else if (this.effectType == 1) {
  46. this.scheduleOnce(() => {
  47. this.node.destroy();
  48. }, 2)
  49. }
  50. else if (this.effectType == 3) {
  51. cc.tween(this.node).set({ scale: 3 }).to(0.5, { scale: 1 }).to(0.5, { opacity: 0 }).call(() => {
  52. this.node.destroy();
  53. }).start();
  54. }
  55. else if (this.effectType == 4) {
  56. cc.tween(this.node).to(1.5, { angle: 720, scale: 0.5 }).to(0.3, { opacity: 0 }).call(() => { this.node.destroy() }).start();
  57. }
  58. else if (this.effectType == 5) {
  59. let ani = this.node.children[0].getComponent(sp.Skeleton);
  60. ani.setCompleteListener(() => { cc.isValid(this.node.isValid) && this.node.destroy(); })
  61. this.scheduleOnce(() => { cc.isValid(this.node.isValid) && this.node.destroy(); }, 2);
  62. }
  63. else if (this.effectType == 6) {
  64. cc.tween(this.node).delay(0.5).to(0.2, { opacity: 0 }).call(() => { this.node.destroy() }).start();
  65. }
  66. else if (this.effectType == 7) {
  67. let icon = this.node.children[0];
  68. cc.tween(icon)
  69. .bezierTo(0.6, cc.Vec2.ZERO, cc.v2(-50, 50), cc.v2(-50 - 50 * Math.random(), -150))
  70. .to(1, { opacity: 0 }, { easing: 'fade' })
  71. .call(() => { this.node.destroy(); })
  72. .start();
  73. }
  74. else if (this.effectType == 8) {
  75. cc.tween(this.node)
  76. .to(0.5, { opacity: 0 })
  77. .call(() => { this.node.destroy(); })
  78. .start();
  79. }
  80. }
  81. // update (dt) {}
  82. }