FHitBoxOpenDoor.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { SpriteActionType } from "../../object/FSprite";
  2. import FHitBox from "./FHitBox";
  3. /**
  4. * 打碎一组箱子后打开门
  5. */
  6. const {ccclass, property} = cc._decorator;
  7. @ccclass
  8. export default class FHitBoxOpenDoor extends FHitBox {
  9. @property({
  10. displayName:'需要打碎的其它箱子',
  11. type:[cc.Node]
  12. })
  13. mOtherBox: Array<cc.Node> = [];
  14. private isClose = false
  15. public hitBox() {
  16. this.onEnd(1)
  17. this.ff.pauseSprite(true)
  18. this.node.removeComponent(cc.PhysicsBoxCollider)
  19. this.node.removeComponent(cc.PhysicsBoxCollider)
  20. let element = this.ff.mainSprite
  21. element.useHammer()
  22. element.playAction2(SpriteActionType.chuizi, false, () => {
  23. this.ff.pauseSprite(false)
  24. element.playAction2(SpriteActionType.stand, true);
  25. element.updateSkin()
  26. })
  27. this.isClose = true
  28. cc.tween(element.node).sequence(
  29. cc.delayTime(0.2),
  30. cc.callFunc(() => {
  31. this.spine.setCompleteListener(() => {
  32. this.node.destroy();
  33. })
  34. this.openDoor()
  35. this.spine.setAnimation(0, 'boom', false);
  36. })
  37. ).start();
  38. }
  39. public openDoor(){
  40. for (let i = 0; i < this.mOtherBox.length; i++) {
  41. const element = this.mOtherBox[i];
  42. if(element.isValid && !element.getComponent(FHitBoxOpenDoor).isClose){
  43. return
  44. }
  45. }
  46. this.pause()
  47. this.moveCamera(this.hide.getPosition(),1,()=>{
  48. this.resume()
  49. if (this.hide && this.hide.isValid) {
  50. this.hide.active = true;
  51. }
  52. })
  53. }
  54. }