ZY_GameScene.js 3.5 KB

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