JG0111_1.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import FqLogin from "../../login/FqLogin";
  2. import { AudioMgr } from "../../main/ViewManage";
  3. import BaseEvent from "../fight/evnet/base/BaseEvent";
  4. /**
  5. * 多组按钮控制开门-解救宠物剧情
  6. */
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class JG0111_1 extends BaseEvent {
  10. @property({
  11. displayName: '替换的图片',
  12. type: cc.Sprite,
  13. })
  14. mIcon: cc.Sprite = null;
  15. @property({
  16. displayName: '未踩上图片',
  17. type: cc.SpriteFrame,
  18. })
  19. mIcon0: cc.SpriteFrame = null;
  20. @property({
  21. displayName: '踩上后的图片',
  22. type: cc.SpriteFrame,
  23. })
  24. mIcon1: cc.SpriteFrame = null;
  25. /**
  26. * 控制的栅栏机关
  27. */
  28. @property({
  29. displayName: '其它开关',
  30. type: [cc.Node],
  31. })
  32. mButtons: Array<cc.Node> = [];
  33. /**
  34. * 控制的栅栏机关
  35. */
  36. @property({
  37. displayName: '控制的机关',
  38. type: [cc.Node],
  39. })
  40. mFenceTrigger: Array<cc.Node> = [];
  41. @property({
  42. displayName: '困住的宠物',
  43. type: cc.Node,
  44. })
  45. mPet: cc.Node = null;
  46. /**
  47. * 机关是否已经结束
  48. */
  49. public isOver = false;
  50. private count = 0;
  51. onLoad(){
  52. super.onLoad();
  53. this.node.zIndex = -9999;
  54. }
  55. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  56. if (other.node.group != 'bullet') {
  57. this.count++
  58. this.onBegin(self.tag)
  59. }
  60. }
  61. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  62. if (other.node.group != 'bullet') {
  63. this.count--
  64. if (this.count <= 0) {
  65. this.count = 0;
  66. this.onEnd(self.tag)
  67. }
  68. }
  69. }
  70. onBegin(tag: number) {
  71. this.mIcon.spriteFrame = this.mIcon1;
  72. this.checkOpen();
  73. }
  74. onEnd(tag: number) {
  75. }
  76. private checkOpen() {
  77. if (this.isOver) {
  78. return
  79. }
  80. this.isOver = true;
  81. this.pause();
  82. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  83. cc.tween(this.node).sequence(
  84. cc.callFunc(() => {
  85. this.showFence(this.mFenceTrigger[0], 'down');
  86. let nodes = this.mFenceTrigger[1].children
  87. for (let i = 0; i < nodes.length; i++) {
  88. const element = nodes[i];
  89. this.showFence(element, 'down');
  90. }
  91. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  92. }),
  93. cc.delayTime(1),
  94. cc.callFunc(() => {
  95. this.resume()
  96. this.mFenceTrigger[0].getComponent(cc.PhysicsBoxCollider).enabled = false;
  97. // for (let i = 0; i < this.mFenceTrigger.length; i++) {
  98. // const element = this.mFenceTrigger[i];
  99. // // element.active = false;
  100. // element.getComponent(cc.PhysicsBoxCollider).enabled = false;
  101. // }
  102. })
  103. ).start();
  104. })
  105. }
  106. private showFence(element, action) {
  107. let nodes = element.children;
  108. for (let i = 0; i < nodes.length; i++) {
  109. const element = nodes[i];
  110. let spine:sp.Skeleton = element.getComponent(sp.Skeleton);
  111. if (spine) {
  112. spine.setAnimation(0, action, false);
  113. }
  114. }
  115. }
  116. }