Gold.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, { PopType } from "../EventName/EventName";
  8. import LocalData from "../LocalData";
  9. import MyComponent from "../Template/MyComponent";
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class Gold extends MyComponent {
  13. Label: cc.Label = null
  14. onLoad(): void {
  15. this.regEvent(EventName.changeGold, this.UpdataGold, this)
  16. }
  17. start() {
  18. let add = this.node.getChildByName("add")
  19. this.Label = this.node.getChildByName("Label").getComponent(cc.Label)
  20. switch (cc.director.getScene().name) {
  21. case 'Game':
  22. add.active = false
  23. break;
  24. case 'Hall':
  25. add.active = true
  26. break;
  27. default:
  28. break;
  29. }
  30. this.Label.string = LocalData.getInstance().getGold().toString()
  31. }
  32. UpdataGold() {
  33. this.Label.string = LocalData.getInstance().getGold().toString()
  34. }
  35. ClickGold() {
  36. cc.log('ClickGold')
  37. //提示看广告拿金币
  38. let temp: PopType = new PopType()
  39. temp.string = '看广告拿金币'
  40. temp.Title = '提示'
  41. temp.OK = () => {
  42. this.OpenAD()
  43. }
  44. temp.Fail = () => {
  45. }
  46. this.Pop(temp)
  47. }
  48. // update (dt) {}
  49. }