CashOutingTip.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class CashOutingTip extends cc.Component {
  10. @property(cc.Node)
  11. node_spotMove: cc.Node = null;
  12. // LIFE-CYCLE CALLBACKS:
  13. // onLoad () {}
  14. start() {
  15. }
  16. // update (dt) {}
  17. onEnable() {
  18. this.intervalMoveSpot();
  19. }
  20. onDisable() {
  21. this.cancelMoveSpot();
  22. }
  23. public interval_spotMove: number = null;
  24. public moveDis: number = 20;
  25. public curMoveNum: number = 0;
  26. public maxMoveNum: number = 2;
  27. intervalMoveSpot() {
  28. this.interval_spotMove = setInterval(() => {
  29. this.curMoveNum += 1;
  30. if (this.curMoveNum > this.maxMoveNum) {
  31. this.curMoveNum = 0;
  32. }
  33. this.node_spotMove.x = this.moveDis * (this.curMoveNum - 1);
  34. },200)
  35. }
  36. cancelMoveSpot() {
  37. if (this.interval_spotMove) {
  38. clearInterval(this.interval_spotMove);
  39. this.interval_spotMove = null;
  40. this.curMoveNum = 0;
  41. this.node_spotMove.x = -this.moveDis;
  42. }
  43. }
  44. }