UIControl.js 6.5 KB

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