FOpenTrigger.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import FqLogin from "../../../login/FqLogin";
  2. import { AudioMgr } from "../../../main/ViewManage";
  3. import FF from "../FF";
  4. import FMap from "../map/FMap";
  5. import FSprite from "../object/FSprite";
  6. /**
  7. * 打开机关
  8. */
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class FOpenTrigger extends cc.Component {
  12. /**
  13. * 控制的栅栏
  14. */
  15. @property([cc.Node])
  16. mFenceTrigger: Array<cc.Node> = [];
  17. @property([cc.Node])
  18. guides: Array<cc.Node> = [];//引导标识
  19. @property(cc.SpriteFrame)
  20. closeFrame: cc.SpriteFrame = null;
  21. private fMap: FMap;
  22. private isOver = false;
  23. onLoad() {
  24. this.fMap = this.node.parent.parent.getComponent(FMap);
  25. // this.mFenceTrigger.forEach(element => {
  26. // this.showFence(element,'open');
  27. // });
  28. }
  29. onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  30. if (this.isOver) {
  31. return;
  32. }
  33. if (other.node.group == 'bullet') {//子弹不能触发
  34. return;
  35. }
  36. this.isOver = true;
  37. this.node.removeComponent(cc.PhysicsBoxCollider);
  38. let ff = this.fMap.ff;
  39. ff.pauseSprite(true);
  40. let camera = this.fMap.mCamera;
  41. let cameraPos = this.mFenceTrigger[0];
  42. let pos = cc.v2();
  43. let winsize = cc.winSize;
  44. pos.x = cameraPos.x - winsize.width / 2;
  45. pos.y = cameraPos.y - winsize.height / 2;
  46. for (let i = 0; i < this.guides.length; i++) {
  47. const element = this.guides[i];
  48. element.destroy();
  49. }
  50. this.guides = [];
  51. let sprite = this.node.getComponent(cc.Sprite);
  52. sprite.spriteFrame = this.closeFrame;
  53. cc.tween(camera.node).sequence(
  54. cc.moveTo(1.5, pos),
  55. cc.callFunc(() => {
  56. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  57. const element = this.mFenceTrigger[i];
  58. this.showFence(element, 'close');
  59. }
  60. ff.main.playerEffectByPath(AudioMgr.openDoor);
  61. }),
  62. cc.delayTime(1),
  63. cc.callFunc(() => {
  64. ff.pauseSprite(false);
  65. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  66. const element = this.mFenceTrigger[i];
  67. element.active = false;
  68. }
  69. FqLogin.commitEvent(this.node.name, '', '');
  70. })
  71. ).start();
  72. }
  73. private showFence(element, action) {
  74. let nodes = element.children;
  75. for (let i = 0; i < nodes.length; i++) {
  76. const element = nodes[i];
  77. let spine = element.getComponent(sp.Skeleton);
  78. if (spine) {
  79. spine.setAnimation(0, action, false);
  80. }
  81. }
  82. }
  83. }