UIControl.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. jumpCurrentData: 0,//当前跳远的值
  29. jumpCurrentTime: 0,//当前跳远的时间
  30. tagDistance_Hero: false,
  31. // tagDistance_Rivel: false,
  32. isCanUpdate: false,//是否跳出更新
  33. //0 跳远 1 标枪
  34. type: 0,
  35. },
  36. // LIFE-CYCLE CALLBACKS:
  37. onLoad () {
  38. this.GameUI = this.getComponent("GameUI");
  39. // this.GameUI.setDistanceNum(22.5);
  40. // this.updateNum_Rivel = 0;
  41. // this.updateNum_Hero = 0;
  42. // this.layoutcount.active = false;
  43. this.offsets = [
  44. 240, 72
  45. ];
  46. },
  47. // start: function () {
  48. // },
  49. startDistance_Hero: function (type, Hero, b) {
  50. this.type = type;
  51. this.Hero = Hero;
  52. // this.tagDistance_Hero = b;
  53. var p = Hero.getPosition();
  54. this.isCanUpdate = b;
  55. var duration = 1000;
  56. if (b)
  57. {
  58. this.setUIActiveShowUIDistance();
  59. if (type === 0) {//0是跳远
  60. // console.log("位置", Hero.getComponent("PlayerState").EndDistance);
  61. this.defaultX_Hero = Hero.getComponent("PlayerState").EndDistance;
  62. this.jumpCurrentTime = Hero.getComponent("PlayerState").JumpTimer;
  63. duration = this.jumpCurrentTime * 1000 + 1500;
  64. }
  65. if (type === 1) {
  66. this.javeTime = Hero.javeTime;
  67. this.defaultX_Hero = p.x;
  68. duration = this.javeTime * 1000 + 1500;
  69. }
  70. setTimeout(function () {
  71. if (this.callBack_Hero != null) {
  72. this.callBack_Hero(this.Label_Hero);
  73. }
  74. if (this.defaultX_Hero)
  75. this.defaultX_Hero = null;
  76. this.isCanUpdate = false;
  77. this.GameUI.setUIActiveTimer_destroy(cc.find('UIDistance'), 0.1);
  78. }.bind(this), duration);
  79. // setTimeout(function () {
  80. // if (this.defaultX_Hero)
  81. // this.defaultX_Hero = null;
  82. // this.isCanUpdate = false;
  83. // }.bind(this), duration);
  84. }
  85. },
  86. setUIActiveShowUIDistance: function () {
  87. // this.GameUI.setUIActiveShow(cc.find('UIDistance'));
  88. // console.log("setUIActiveShowUIDistance");
  89. this.GameUI.displayUIDistance();
  90. },
  91. callBack_Rivel: function () {
  92. },
  93. /**
  94. * 谁想知道结果 就谁调用这个方法 获取距离的方法
  95. * @param callBack
  96. */
  97. setCallBack_Rivel: function (callBack) {
  98. this.callBack_Rivel = callBack;
  99. },
  100. callBack_Hero: function () {
  101. },
  102. /**
  103. * 谁想知道结果 就谁调用这个方法 获取距离的方法
  104. * @param callBack
  105. */
  106. setCallBack_Hero: function (callBack) {
  107. this.callBack_Hero = callBack;
  108. },
  109. update: function (dt) {
  110. if (!this.isCanUpdate)
  111. return;
  112. // if (this.tagDistance_Hero) {
  113. var p = this.Hero.getPosition();
  114. if (this.type === 1 && this.defaultX_Hero != null) {
  115. this.calculationX_Hero = p.x - this.defaultX_Hero;
  116. var showX = this.calculationX_Hero / this.offsets[this.type];
  117. // var Label = this.count.getComponent("cc.Label");
  118. var Label = this.Label_Hero = showX.toFixed(2);
  119. this.GameUI.setDistanceNum(Label);
  120. // CustomLog("记录位置",this.calculationX_Hero);
  121. CustomLog("标枪移动 X", Label);
  122. }
  123. // this.updateNum_Hero++;
  124. //跳远时候
  125. if (this.type === 0 && this.defaultX_Hero != null) {
  126. // var p = this.Hero.getPosition();
  127. this.jumpCurrentData += dt * 4;
  128. this.jumpCurrentData = this.jumpCurrentData > this.defaultX_Hero ? this.defaultX_Hero : this.jumpCurrentData;
  129. var Label = this.Label_Hero = this.jumpCurrentData.toFixed(2);
  130. this.GameUI.setDistanceNum(Label);
  131. // console.log(this.Label_Hero);
  132. }
  133. // }
  134. // if (this.tagDistance_Rivel) {
  135. // var p = this.Rivel.getPosition();
  136. // // CustomLog("记录位置",p.x);
  137. // if (this.defaultX_Rivel != null) {
  138. // this.calculationX_Rivel = p.x - this.defaultX_Rivel;
  139. // var showX = this.calculationX_Rivel / this.offsets[this.type];
  140. // // var Label = this.count.getComponent("cc.Label");
  141. // var Label = this.Label_Rivel = showX.toFixed(2);
  142. // // this.GameUI.setDistanceNum(Label);
  143. // // CustomLog("偏移量 X",showX);
  144. // }
  145. // if (this.updateNum_Rivel == 0) {
  146. // // CustomLog("记录位置 开始 X",p.x);
  147. // }
  148. // this.updateNum_Rivel++;
  149. // // console.log(333);
  150. // }
  151. },
  152. setImage_Player1: function (src) {
  153. this.GameUI.setImage_Player1(src);
  154. },
  155. setImage_Player2: function (src) {
  156. this.GameUI.setImage_Player2(src);
  157. },
  158. setName_Player1: function (name) {
  159. this.GameUI.setName_Player1(name);
  160. },
  161. setName_Player2: function (name) {
  162. this.GameUI.setName_Player2(name);
  163. },
  164. setName_Gender1: function (name) {
  165. this.GameUI.setName_Gender1(name);
  166. },
  167. setName_Gender2: function (name) {
  168. this.GameUI.setName_Gender2(name);
  169. },
  170. // update (dt) {},
  171. });