NewOpenRedBag.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import Util from "../../../before/util/Util";
  2. import { AdFun } from "../../data/AdData";
  3. import { VideoAdType } from "../../data/GameData";
  4. const { ccclass, property } = cc._decorator;
  5. @ccclass
  6. export default class NewOpenRedBag extends cc.Component{
  7. @property({displayName: '数字组', type: cc.Label})
  8. private lbl_value: cc.Label[] = [];
  9. start(){
  10. this.showChangePart();
  11. }
  12. update(dt)
  13. {
  14. if (gData.reward.adData) {
  15. this.showWatchAdReward();
  16. gData.turnable.adData = null;
  17. }
  18. }
  19. private showWatchAdReward()
  20. {
  21. if(gData.reward.adData)
  22. {
  23. let v= '0.30';
  24. v.replace('.','');
  25. let c = v.split('');
  26. for(let i = 0; i != this.lbl_value.length; ++i)
  27. {
  28. if(i < c.length)
  29. {
  30. this.lbl_value[i].string = c[i];
  31. }else
  32. {
  33. this.lbl_value[i].string = '0';
  34. }
  35. }
  36. }
  37. }
  38. showChangePart() {
  39. //this.changePart.active = true
  40. let len = this.lbl_value.length;
  41. this.schedule(() => {
  42. for (var i = 0; i < len; i++) {
  43. let ran = Util.rnd(0, 9);
  44. this.lbl_value[i].string = `${ran}`;
  45. }
  46. }, 0.1)
  47. }
  48. private clickOpenBtn(){
  49. mk.audio.playEffect("button");
  50. mk.ad.videoAdType = VideoAdType.StartQiPaoRedBag;
  51. mk.ad.watchAd((success: boolean) => {
  52. mk.console.log("watchAD:" + success);
  53. if (success) {
  54. gData.adData.watchVideo(AdFun.bubble);
  55. }
  56. });
  57. }
  58. private clickCloseBtn(){
  59. mk.audio.playEffect("closeButton");
  60. }
  61. }