b48328cc-e2cd-4bcf-b096-987a993e28c8.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. "use strict";
  2. cc._RF.push(module, 'b4832jM4s1Lz7CWmHqZPijI', 'ZY_GameScene');
  3. // Script/ZY_GameScene.js
  4. "use strict";
  5. var GameEvent = require('GameEvent');
  6. var ZYGameTool = require('GameTool');
  7. cc.Class({
  8. "extends": cc.Component,
  9. properties: {
  10. gameManger: cc.Prefab,
  11. gamePauseLayer: cc.Prefab,
  12. helpNode: cc.Prefab,
  13. gameEndLayer: cc.Prefab,
  14. gameTipLyaer: cc.Prefab,
  15. _gameManger: null
  16. },
  17. // LIFE-CYCLE CALLBACKS:
  18. onLoad: function onLoad() {
  19. this.createGameLayer();
  20. },
  21. start: function start() {
  22. var _this = this;
  23. cc.game.on(GameEvent.EventType.GANE_PAUSE, function () {
  24. _this.pauseClick();
  25. }, this);
  26. cc.game.on(GameEvent.EventType.GANE_HELP, function () {
  27. _this.helpClick();
  28. }, this);
  29. cc.game.on(GameEvent.EventType.GANE_FAIL, function () {
  30. _this.gameFaild();
  31. }, this);
  32. cc.game.on(GameEvent.EventType.GAME_TIP, function () {
  33. _this.openTip();
  34. }, this);
  35. },
  36. createGameLayer: function createGameLayer() {
  37. if (this._gameManger) {
  38. this._gameMange.removeFromParent();
  39. this._gameMange = null;
  40. }
  41. if (Module.GameManager) Module.GameManager = null;
  42. this._gameManger = cc.instantiate(this.gameManger);
  43. this._gameManger.parent = this.node;
  44. this._gameManger.setAnchorPoint(cc.v2(0.5, 0.5));
  45. this._gameManger.setContentSize(cc.v2(0, 0));
  46. this._gameManger.setPosition(cc.v2(0, 0));
  47. },
  48. //提示
  49. openTip: function openTip() {
  50. var gameTip = cc.instantiate(this.gameTipLyaer); // console.log("-layer.width: " , gameTip.getChildByName("layer").width);
  51. gameTip.parent = this.node;
  52. gameTip.zIndex = 1000;
  53. Module.GameTipLayer.call(function (num) {
  54. if (num > 0) {
  55. Module.GameManager.txtTip("Congratulations on getting" + num + "gold coins");
  56. } else {
  57. Module.GameManager.txtTip("Watch video failed, no gold coins");
  58. }
  59. }.bind(this));
  60. },
  61. //失败
  62. gameFaild: function gameFaild() {
  63. var gameFaildNode = cc.instantiate(this.gameEndLayer);
  64. gameFaildNode.zIndex = 100;
  65. gameFaildNode.parent = this.node;
  66. Module.GameFaildLayer.call(function (state) {
  67. console.log("state: ", state);
  68. if (state) {
  69. Module.GameManager.resurrenction();
  70. }
  71. }.bind(this));
  72. },
  73. restStart: function restStart() {
  74. this._gameManger.removeFromParent();
  75. this._gameManger = null;
  76. this.node.runAction(cc.sequence(cc.delayTime(0.2), cc.callFunc(function () {
  77. this.createGameLayer();
  78. }.bind(this))));
  79. },
  80. pauseClick: function pauseClick() {
  81. var pauseLayer = cc.instantiate(this.gamePauseLayer);
  82. pauseLayer.parent = this.node;
  83. pauseLayer.zIndex = 1000;
  84. Module.GamePauseLayer.call(function (name) {
  85. gameLocalData.save(Module.GameManager);
  86. if (name === "backGameBtn") {} else if (name === "restGameBtn") {
  87. gameLocalData.clear();
  88. this.restStart();
  89. } else if (name === "backHomeBtn") {
  90. cc.director.loadScene("homeScene");
  91. }
  92. }.bind(this));
  93. },
  94. helpClick: function helpClick() {
  95. var helpNode = cc.instantiate(this.helpNode);
  96. helpNode.parent = this.node;
  97. helpNode.zIndex = 1000;
  98. ZYGameTool.getInstance().setIntegerForKey(localDataItem.gameGuide, 0);
  99. Module.GameHelpLayer.setParam(false);
  100. } // update (dt) {},
  101. });
  102. cc._RF.pop();