UIClickEft.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { GameEvent } from "../../../data/const/EventConst";
  2. import { ViewZOrder } from "../../../data/const/ViewZOrder";
  3. import GameDataCenter from "../../../data/GameDataCenter";
  4. import EventMng from "../../../manager/EventMng";
  5. import SpineNode from "../../../utils/SpineNode";
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class UIClickEft extends cc.Component {
  9. clickEft: SpineNode
  10. protected onEnable(): void {
  11. EventMng.on(GameEvent.ON_CLICK, this.onClick, this)
  12. }
  13. protected onDisable(): void {
  14. EventMng.off(GameEvent.ON_CLICK, this.onClick, this)
  15. }
  16. start() {
  17. cc.game.addPersistRootNode(this.node)
  18. this.node.zIndex = ViewZOrder.ClickEft
  19. let node = new SpineNode("spine", "effect_dianji01/effect_dianji01", 1, "animation", false, 1, () => {
  20. this.clickEft = node
  21. // node.spine.setCompleteListener((trackEntry: sp.spine.TrackEntry) => {
  22. // this.clickEft.node.active = false
  23. // })
  24. // node.active = false
  25. this.clickEft.spine.setCompleteListener(this.OnCompleteListener.bind(this));
  26. }, true)
  27. node.parent = this.node
  28. node.x = -200
  29. }
  30. onClick(event) {
  31. GameDataCenter.time.guideRuoTime = 0
  32. if (this.clickEft == null) {
  33. return
  34. }
  35. this.clickEft.active = true;
  36. this.clickEft.x = event.getLocationX()
  37. this.clickEft.y = event.getLocationY()
  38. this.clickEft.spine.setAnimation(0, "animation", false)
  39. }
  40. OnCompleteListener() {
  41. this.clickEft.active = false;
  42. }
  43. }