init.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. const PlayerStateStatic = require('PlayerState');
  11. const GameStatesStatic = require('GameStates');
  12. cc.Class({
  13. extends: cc.Component,
  14. properties: {
  15. HeroP: {
  16. // ATTRIBUTES:
  17. default: null, // The default value will be used only when the component attaching
  18. type: cc.Prefab // to a node for the first time
  19. },
  20. LevelP: {
  21. // ATTRIBUTES:
  22. default: null, // The default value will be used only when the component attaching
  23. type: cc.Prefab // to a node for the first time
  24. },
  25. // bar: {
  26. // get () {
  27. // return this._bar;
  28. // },
  29. // set (value) {
  30. // this._bar = value;
  31. // }
  32. // },
  33. },
  34. // LIFE-CYCLE CALLBACKS:
  35. onLoad : function() {
  36. this.CamerarMennager = cc.find("CamerarMennager");
  37. cc.log("游戏开始le ",this.CamerarMennager);
  38. this.Hero = cc.instantiate(this.HeroP);
  39. this.Level = cc.instantiate(this.LevelP);
  40. this.initGame();
  41. },
  42. initGame : function () {
  43. setTimeout(function () {
  44. this.addHero();
  45. cc.find('TouchLayout').getComponent('NodeTouch').count = 0;
  46. }.bind(this),0)
  47. },
  48. addHero : function (data) {
  49. cc.find('Canvas').getComponent('GameStates').CurrentProgress = GameStatesStatic.GameProgress.default;
  50. this.CamerarMennager.parent = cc.director.getScene();
  51. if (cc.find("Hero")!=null) {
  52. // cc.log("有没有什么镜头",);
  53. cc.find("Hero").getComponent("PlayerState").CurrentInZoneType = PlayerStateStatic.ZoneType.None;
  54. cc.find("Hero").destroy();
  55. this.Hero = cc.instantiate(this.HeroP);
  56. }
  57. if (cc.find("Level")!=null) {
  58. cc.find("Level").destroy();
  59. this.Level = cc.instantiate(this.LevelP);
  60. }
  61. this.Level.parent = cc.director.getScene();
  62. this.Hero.parent = cc.director.getScene();
  63. if (data == null) {
  64. this.CamerarMennager.getComponent("CamerarMennager").removeTargets();
  65. this.CamerarMennager.getComponent("CamerarMennager").addTargets(this.Level);
  66. this.CamerarMennager.getComponent("CamerarMennager").addTargets(this.Hero);
  67. this.Hero.setPosition(370+740,640);
  68. }else{
  69. }
  70. this.CamerarMennager.parent = this.Hero;
  71. },
  72. // start () {
  73. //
  74. // },
  75. // update (dt) {
  76. // cc.log(cc.find("Level").getComponent('LevelControl').name);
  77. // },
  78. });