titlelayoutmanager.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. // onLoad () {},
  31. start () {
  32. let layout = UtilsNode.getNode("layout",this.node);
  33. let one = UtilsNode.getNode("one",layout);
  34. let two = UtilsNode.getNode("two",layout);
  35. let reset = this.resetbutton = UtilsNode.getNode("reset",layout);
  36. app.titlelayout = this;
  37. UtilsNode.setOn(one,function () {
  38. app.bg.one();
  39. }.bind(this));
  40. UtilsNode.setOn(two,function () {
  41. app.bg.two();
  42. }.bind(this));
  43. UtilsNode.setOn(reset,function () {
  44. app.bg.reset();
  45. this.hideButton(false);
  46. }.bind(this));
  47. let info = this.info = UtilsNode.getNode("info",layout);
  48. let info1 = UtilsNode.getNode("info1",info);
  49. let info2 = UtilsNode.getNode("info2",info);
  50. // this.x = this.info.x;
  51. // this.y = this.info.y;
  52. this.infos = [];
  53. this.infos.push(info1);
  54. this.infos.push(info2);
  55. this.infosp = [];
  56. this.infosp.push({x:info1.x,y:info1.y});
  57. this.infosp.push({x:info2.x,y:info2.y});
  58. let title = this.title = UtilsNode.getNode("title",layout);
  59. let progresslayout = UtilsNode.getNode("progresslayout",title);
  60. let progress1 = UtilsNode.getNode("progress1",progresslayout);
  61. let progress2 = UtilsNode.getNode("progress2",progresslayout);
  62. let player_showbg1 = UtilsNode.getNode("player_showbg1",progresslayout);
  63. let player_showbg2 = UtilsNode.getNode("player_showbg2",progresslayout);
  64. this.playerprogress = [];
  65. this.playerprogress.push(progress1);
  66. this.playerprogress.push(progress2);
  67. this.player_showbgs = [];
  68. this.player_showbgs.push(player_showbg1);
  69. this.player_showbgs.push(player_showbg2);
  70. this.fristEndTag = false;
  71. },
  72. //重置
  73. _init : function(){
  74. this.showinfoinit();
  75. this.setInitProgress();
  76. },
  77. // startGame : function () {
  78. // this.resetbutton.active = false;
  79. // },
  80. hideButton : function (b) {
  81. if (b) {
  82. setTimeout(function () {
  83. this.resetbutton.active = b;
  84. }.bind(this),1000)
  85. }else{
  86. this.resetbutton.active = b;
  87. }
  88. // this.showinfoinit();
  89. },
  90. showinfo: function (b,type,num) {
  91. if (!b) {
  92. this.infos[type].active = b;
  93. return;
  94. }else{
  95. if (!this.infos[type].active) {
  96. this.infos[type].active = b;
  97. this.info.stopAllActions();
  98. this.infos[type].x = this.infosp[type].x;
  99. this.infos[type].y = this.infosp[type].y;
  100. let myAction = cc.repeatForever(cc.sequence(cc.moveBy(0.5, cc.v2(0,-20)),cc.moveBy(0.5, cc.v2(0,+20))));
  101. this.infos[type].runAction(myAction);
  102. }
  103. this.infosTitle = [];
  104. let infobg_lose = UtilsNode.getNode("infobg_lose",this.infos[type]);
  105. let infobg_win = UtilsNode.getNode("infobg_win",this.infos[type]);
  106. // this.infosTitle.push(infobg_win);
  107. // this.infosTitle.push(infobg_lose);
  108. let text = UtilsNode.getNode("text",this.infos[type]);
  109. let title = "";
  110. if (type == 0) {
  111. // title = "对手落后"+num+"步";
  112. title = num;
  113. infobg_lose.active = false;
  114. infobg_win.active = true;
  115. }else if (type == 1) {
  116. // title = "你落后"+num+"步";
  117. title = num;
  118. infobg_lose.active = true;
  119. infobg_win.active = false;
  120. }
  121. text.getComponent(cc.Label).string = title;
  122. }
  123. },
  124. showinfoinit: function () {
  125. for (var i = 0; i < this.infos.length; i++) {
  126. this.infos[i].active = false;
  127. }
  128. },
  129. setProgress : function (playertype,num,max) {
  130. let temp = UtilsNode.getPercentage(num,max);
  131. this.playerprogress[playertype].getComponent(cc.Label).string = temp+"%";
  132. // console.log("当前进来是啥",playertype,num,max,"百分比",UtilsNode.getPercentage(num,max));
  133. if (temp>=80) {
  134. this.setFristEnd(playertype);
  135. }
  136. },
  137. setInitProgress : function () {
  138. for (let i = 0; i <this.playerprogress.length ; i++) {
  139. this.playerprogress[i].getComponent(cc.Label).string = 0+"%";
  140. }
  141. },
  142. //只显示一次的 快到终点提示
  143. setFristEnd : function (type) {
  144. // this.player_showbgs
  145. if (!this.fristEndTag) {
  146. if (type == 0) {
  147. app.bgm.playkuaidaozhongdian();
  148. }else{
  149. app.bgm.playkuaidaozhongdian();
  150. }
  151. this.fristEndTag = true;
  152. this.player_showbgs[type].active = true;
  153. setTimeout(function () {
  154. this.player_showbgs[type].active = false;
  155. }.bind(this),2000)
  156. }
  157. },
  158. // update (dt) {},
  159. });