ManageAd.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. bottomMenuNode: {
  14. default: null,
  15. type: cc.Node,
  16. serializable: true,
  17. },
  18. oldHeight: 0,
  19. },
  20. // LIFE-CYCLE CALLBACKS:
  21. // onLoad () {},
  22. start() {
  23. //记录现在ui的bottom
  24. this.oldHeight = this.bottomMenuNode.getComponent(cc.Widget).bottom;
  25. // this.onPlayBannerAd();
  26. },
  27. // update (dt) {},
  28. onCloseBannerAd() {
  29. this.bottomMenuNode.getComponent(cc.Widget).bottom = this.oldHeight;
  30. AD.closeAd();
  31. },
  32. onPlayBannerAd() {
  33. let that = this;
  34. AD.playAd((res) => {
  35. if (res.isPlay) {
  36. // console.log('that.oldHeight - resResize.height', that.oldHeight + res.height, that.oldHeight, res.height);
  37. that.bottomMenuNode.getComponent(cc.Widget).bottom = that.oldHeight + res.height * 2;
  38. }
  39. }, (resResize) => {
  40. }, (err) => {
  41. console.error('拉取广告失败');
  42. that.bottomMenuNode.getComponent(cc.Widget).bottom = that.oldHeight;
  43. })
  44. }
  45. });