Fly.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import EventName from "../EventName/EventName";
  8. import LocalData from "../LocalData";
  9. import { AwardType } from "../Pop/Award";
  10. import MyComponent from "../Template/MyComponent";
  11. import RewardMnr from "../Template/RewardMnr";
  12. const { ccclass, property } = cc._decorator;
  13. //飞
  14. @ccclass
  15. export default class Fly extends MyComponent {
  16. @property(cc.Label)
  17. Count: cc.Label = null;
  18. @property(cc.Sprite)
  19. CountBg_Video: cc.Sprite = null;
  20. @property(cc.SpriteFrame)
  21. CountBg: cc.SpriteFrame = null;
  22. @property(cc.SpriteFrame)
  23. Video: cc.SpriteFrame = null;
  24. // LIFE-CYCLE CALLBACKS:
  25. // onLoad () {}
  26. start() {
  27. this.regEvent(EventName.changeFlyCount, this.changeFlyCount, this)
  28. this.node.on(cc.Node.EventType.TOUCH_START, this.UseFly, this);//当手指在背景上移动时触发move事件
  29. cc.systemEvent.emit(EventName.changeFlyCount)
  30. }
  31. UseFly() {
  32. if (LocalData.getInstance().getFlyCount() > 0) {
  33. RewardMnr.getInstance().PropFlyjump(1)
  34. } else {
  35. cc.systemEvent.emit(EventName.Tips, `起飞去看广告一次的逻辑`)
  36. RewardMnr.getInstance().PopAward(AwardType.Fly)
  37. LocalData.getInstance().setFlyCount(1, '+')
  38. }
  39. }
  40. changeFlyCount() {
  41. if (LocalData.getInstance().getFlyCount() > 0) {
  42. this.CountBg_Video.spriteFrame = this.CountBg
  43. this.Count.string = LocalData.getInstance().getFlyCount().toString()
  44. } else {
  45. this.CountBg_Video.spriteFrame = this.Video
  46. this.Count.string = ''
  47. }
  48. }
  49. // update (dt) {}
  50. }