Supjump.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 Supjump 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.changeSupjumpCount, this.changeSupjumpCount, this)
  28. this.node.on(cc.Node.EventType.TOUCH_START, this.useSupjump, this);//当手指在背景上移动时触发move事件
  29. cc.systemEvent.emit(EventName.changeSupjumpCount)
  30. }
  31. useSupjump() {
  32. if (LocalData.getInstance().getSupjumpCount() > 0) {
  33. RewardMnr.getInstance().PropUseSupjump(1)
  34. } else {
  35. // cc.systemEvent.emit(EventName.Tips, `超级跳去看广告一次的逻辑`)
  36. RewardMnr.getInstance().PopAward(AwardType.ChaojiTiao)
  37. LocalData.getInstance().setSupjumpCount(1, '+')
  38. }
  39. }
  40. changeSupjumpCount() {
  41. if (LocalData.getInstance().getSupjumpCount() > 0) {
  42. this.CountBg_Video.spriteFrame = this.CountBg
  43. this.Count.string = LocalData.getInstance().getSupjumpCount().toString()
  44. } else {
  45. this.CountBg_Video.spriteFrame = this.Video
  46. this.Count.string = ''
  47. }
  48. }
  49. // update (dt) {}
  50. }