FHitBox.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { AudioMgr } from "../../../../main/ViewManage";
  2. import { SpriteActionType } from "../../object/FSprite";
  3. import BaseEvent from ".././base/BaseEvent";
  4. /**
  5. * 能被打碎的箱子
  6. */
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class FHitBox extends BaseEvent {
  10. @property(sp.Skeleton)
  11. spine: sp.Skeleton = null;
  12. @property({
  13. displayName: '靠近的提示',
  14. type: cc.Node
  15. })
  16. icon: cc.Node = null;
  17. @property({
  18. displayName: '打碎后显示',
  19. type: cc.Node
  20. })
  21. hide: cc.Node = null;
  22. @property({
  23. displayName: '提示图标',
  24. type: cc.SpriteFrame
  25. })
  26. mTipsIcon: cc.SpriteFrame = null;
  27. private isOver = false;
  28. onLoad() {
  29. super.onLoad()
  30. if (this.icon) {
  31. this.icon.active = false;
  32. }
  33. if (this.hide && this.hide.isValid) {
  34. this.hide.active = false;
  35. }
  36. }
  37. start() {
  38. if (this.hide) {
  39. if (this.ff.mMap.checkIn(this.hide.name)) {
  40. this.node.destroy()
  41. }
  42. }
  43. }
  44. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  45. if (other.node.group == 'bullet') {
  46. this.onBegin(self.tag)
  47. }
  48. }
  49. onBegin(tag: number) {
  50. if (this.isOver) {
  51. return
  52. }
  53. this.isOver = true
  54. this.hitBox()
  55. }
  56. public hitBox() {
  57. // this.onEnd(1)
  58. // this.ff.pauseSprite(true)
  59. this.node.removeComponent(cc.PhysicsBoxCollider)
  60. this.node.removeComponent(cc.PhysicsBoxCollider)
  61. // element.useHammer()
  62. // element.playAction2(SpriteActionType.chuizi, false, () => {
  63. // this.ff.pauseSprite(false)
  64. // element.playAction2(SpriteActionType.stand, true);
  65. // element.updateSkin()
  66. // })
  67. if (this.spine) {
  68. this.spine.setCompleteListener(() => {
  69. this.node.destroy();
  70. })
  71. if (this.hide && this.hide.isValid) {
  72. this.hide.active = true;
  73. }
  74. this.spine.setAnimation(0, 'boom', false);
  75. }
  76. this.ff.main.playerEffectByPath(AudioMgr.wooden);
  77. }
  78. }