FAltarGear.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { HttpStateType, ReveData } from "../../../../util/CHttp";
  2. import FMap from "../../map/FMap";
  3. import FAltarLight from "./FAltarLight";
  4. const SpineName = {
  5. IDLE: "idle",
  6. IDLE2: "idle2",
  7. CLOSE: "close",
  8. OPEN: "open"
  9. }
  10. /**
  11. * 事件机关
  12. */
  13. const { ccclass, property } = cc._decorator;
  14. @ccclass
  15. export default class FAltarGear extends cc.Component {
  16. @property({
  17. displayName: '对应的地图物件'
  18. })
  19. public mapGoodId: string = '27';
  20. @property({
  21. type: [cc.Node],
  22. displayName: '祭坛灯柱'
  23. })
  24. public altarLight: Array<cc.Node> = [];
  25. private map: FMap = null;
  26. onLoad() {
  27. this.map = this.node.parent.parent.getComponent(FMap);
  28. }
  29. /**
  30. * 检查灯柱点亮情况
  31. */
  32. public check() {
  33. for (let i = 0; i < this.altarLight.length; i++) {
  34. const element = this.altarLight[i];
  35. let altarLight = element.getComponent(FAltarLight)
  36. if (!altarLight.spine.active) {
  37. return false;
  38. }
  39. }
  40. this.openGear();
  41. return true
  42. }
  43. private openGear() {
  44. let ff = this.map.ff;
  45. ff.pauseSprite(true);
  46. this.moveCamera(() => {
  47. this.node.zIndex = -9999;
  48. let nodes = this.node.children;
  49. nodes.forEach(element => {
  50. let spine = element.children[0].getComponent(sp.Skeleton);
  51. if (spine) {
  52. spine.setCompleteListener(() => {
  53. element.getComponent(cc.PhysicsBoxCollider).enabled = false;
  54. });
  55. spine.setAnimation(0, SpineName.OPEN, false);
  56. }
  57. });
  58. });
  59. }
  60. private moveCamera(callFunc: Function) {
  61. let map = this.map;
  62. let camera = map.mCamera;
  63. let pos = cc.v2();
  64. let winsize = cc.winSize;
  65. pos.x = this.node.x - winsize.width / 2;
  66. pos.y = this.node.y - winsize.height / 2;
  67. cc.tween(camera.node).sequence(
  68. cc.moveTo(1, pos).easing(cc.easeOut(1)),
  69. cc.callFunc(() => {
  70. callFunc && callFunc();
  71. }),
  72. cc.delayTime(1),
  73. cc.callFunc(() => {
  74. map.ff.pauseSprite(false);
  75. })
  76. ).start()
  77. }
  78. }