FHitMound.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { SpriteActionType } from "../object/FSprite";
  2. import BaseEvent from "./base/BaseEvent";
  3. /**
  4. * 土堆
  5. */
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class FHitMound extends BaseEvent {
  9. @property(sp.Skeleton)
  10. spine: sp.Skeleton = null;
  11. @property({
  12. displayName: '靠近的提示',
  13. type: cc.Node
  14. })
  15. icon: cc.Node = null;
  16. @property({
  17. displayName: '打碎后显示',
  18. type: cc.Node
  19. })
  20. hide: cc.Node = null;
  21. @property({
  22. displayName: '提示图标',
  23. type: cc.SpriteFrame
  24. })
  25. mTipsIcon: cc.SpriteFrame = null;
  26. @property({
  27. displayName: '敲击次数',
  28. })
  29. mHitCount: number = 1;
  30. private hitCount = 0;
  31. onLoad() {
  32. super.onLoad()
  33. if (this.icon) {
  34. this.icon.active = false;
  35. }
  36. if (this.hide && this.hide.isValid) {
  37. this.hide.active = false;
  38. }
  39. }
  40. onBegin(tag: number) {
  41. if (tag == 1) {
  42. this.showOpt(this.mTipsIcon, () => {
  43. this.hitCount ++
  44. let element = this.ff.mainSprite
  45. element.useHammer()
  46. element.playAction2(SpriteActionType.chuizi, false, () => {
  47. this.ff.pauseSprite(false)
  48. element.playAction2(SpriteActionType.stand, true);
  49. element.updateSkin()
  50. })
  51. if(this.hitCount >= this.mHitCount){
  52. this.hitBox()
  53. }else{
  54. this.spine.setAnimation(0, 'hit', false);
  55. }
  56. })
  57. } else if (tag == 2) {
  58. if (this.icon) {
  59. this.icon.active = true;
  60. }
  61. }
  62. }
  63. onEnd(tag: number) {
  64. if (tag == 1) {
  65. this.closeOpt()
  66. } else if (tag == 2) {
  67. if (this.icon) {
  68. this.icon.active = false;
  69. }
  70. }
  71. }
  72. private hitBox() {
  73. this.onEnd(1)
  74. this.ff.pauseSprite(true)
  75. this.node.removeComponent(cc.PhysicsBoxCollider)
  76. this.node.removeComponent(cc.PhysicsBoxCollider)
  77. let element = this.ff.mainSprite
  78. element.useHammer()
  79. element.playAction2(SpriteActionType.chuizi, false, () => {
  80. this.ff.pauseSprite(false)
  81. element.playAction2(SpriteActionType.stand, true);
  82. element.updateSkin()
  83. })
  84. cc.tween(element.node).sequence(
  85. cc.delayTime(0.2),
  86. cc.callFunc(() => {
  87. this.spine.setCompleteListener(() => {
  88. this.node.destroy();
  89. })
  90. if (this.hide && this.hide.isValid) {
  91. this.hide.active = true;
  92. }
  93. this.spine.setAnimation(0, 'dead', false);
  94. })
  95. ).start();
  96. }
  97. }