Collect.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. },
  5. start () {
  6. this._init();
  7. this.diamondCount1 = 1;
  8. this.diamondCount2 = 3;
  9. this.diamondCount3 = 5;
  10. this.diamondCount4 = 4;
  11. this.diamondCount = this.diamondCount3;
  12. this.tests = true;
  13. // GlobalD
  14. },
  15. playScale : function(){
  16. this.diamond.y = this._y;
  17. this.diamond.opacity = 255;
  18. this.diamond.stopAllActions();
  19. var s = cc.sequence(cc.scaleTo(0.5, 2.5),cc.scaleTo(0.5, 2));
  20. var repeat = cc.repeatForever(s);
  21. this.diamond.runAction(repeat);
  22. var s1 = cc.sequence(cc.rotateTo(0.1, -5),cc.rotateTo(0.1, 5));
  23. var r = cc.repeatForever(s1);
  24. this.diamond.runAction(r);
  25. this.onClickTag = true;
  26. },
  27. _addPrefab : function(callback){
  28. cc.loader.loadRes("prefab/diamond", function (err, texture) {
  29. this.diamond = cc.instantiate(texture);
  30. this.diamond.name = "diamond";
  31. var tempNode = this.node;
  32. if (tempNode.getChildByName(this.diamond.name)!=null) {
  33. tempNode.getChildByName(this.diamond.name).destroy();
  34. }
  35. tempNode.addChild(this.diamond);
  36. this.diamond.x = this._x;
  37. this.diamond.y = this._y;
  38. this.diamond.active = false;
  39. if (callback != null) {
  40. callback();
  41. }
  42. }.bind(this));
  43. },
  44. _init: function () {
  45. this.GoldCoin = cc.find("Canvas/UICamera/GoldCoin");
  46. this.diamondIcon = cc.find("Canvas/UICamera/GoldCoin/DiamondIcon");
  47. this.canvas = cc.find("Canvas");
  48. //0 未播放 1正播放
  49. this.state = 0;
  50. this.TipName = '';
  51. this._x = 0;
  52. this._y = this.node.height/2;
  53. this.onClickTag = false;
  54. this.count = 0;
  55. this._addPrefab(function () {
  56. this.diamond.active = true;
  57. // console.log("出来了");
  58. this.diamond.x = this._x;
  59. this.diamond.y = this._y;
  60. this.diamond.opacity = 0;
  61. // if (this.tests) {
  62. // this.playScale();
  63. // this.count = 7;
  64. // this.diamond.opacity = 255;
  65. // this.tests = false;
  66. // }
  67. // UtilsWX.shareMenu();
  68. this.diamond.on(cc.Node.EventType.TOUCH_END, function (event) {
  69. // cc.log("点了钻石",event.getLocation());
  70. // console.log("点了钻石",this.count , this.diamondCount1);
  71. // UtilsWX.sharebtn();
  72. // this.addCount();
  73. let touchPos = event.getLocation();
  74. this.harvest(touchPos);
  75. }.bind(this));
  76. }.bind(this));
  77. },
  78. //判断是否可以
  79. getOnClickTag : function(){
  80. // console.log("点击钻石 之后",this.onClickTag);
  81. return this.onClickTag;
  82. },
  83. addCount : function () {
  84. // var buildingsInfo = this.node.getComponent("buildingsInfo");
  85. // if (buildingsInfo!=null) {
  86. //
  87. // if (buildingsInfo.buildInfo.buildType != 1) {
  88. // return;
  89. // }
  90. // }
  91. this.count++;
  92. if (this.count == this.diamondCount) {
  93. this.playScale();
  94. }else if(this.count == this.diamondCount1) {
  95. this.diamond.opacity = 50;
  96. this.diamond.scale = 1;
  97. this.upDown();
  98. }else if(this.count == this.diamondCount2) {
  99. this.diamond.opacity = 100;
  100. this.diamond.scale = 1.25;
  101. }else if(this.count == this.diamondCount3) {
  102. this.diamond.opacity = 150;
  103. this.diamond.scale = 2;
  104. }else if (this.count >= 6) {
  105. // this.harvest();
  106. }
  107. },
  108. upDown : function(){
  109. var s = cc.sequence(cc.moveBy(0.5, 0,25),cc.moveBy(0.5, 0,-25));
  110. var f = cc.repeatForever(s);
  111. this.diamond.runAction(f)
  112. },
  113. harvest : function (touchPos) {
  114. if (this.count < this.diamondCount1) {
  115. return;
  116. }
  117. var tempCount = this.count;
  118. this.count = 0;
  119. this.diamond.opacity = 255;
  120. let DiamondIcon = cc.find('Canvas').getChildByName('UICamera').getChildByName('BelowTheMask').getChildByName('TopLabel').getChildByName('Diamond').getChildByName('DiamondIcon');
  121. let Pos = DiamondIcon.parent.parent.parent.parent.convertToNodeSpaceAR(touchPos);
  122. this.diamond.parent = DiamondIcon.parent.parent.parent.parent;
  123. this.diamond.setPosition(Pos);
  124. let Duration = 0.5;
  125. var pos1 = DiamondIcon.convertToWorldSpaceAR(this.diamond.parent.getPosition());
  126. var pos2 = this.diamond.parent.convertToNodeSpaceAR(pos1);
  127. var MoveAnim = cc.moveTo(Duration,pos2);
  128. // var jump = cc.jumpBy(0.5, 0, 200, 100, 1);
  129. this.Colortag = true;
  130. var finished = cc.callFunc(function () {
  131. // this.callbackstop = function () {
  132. // this.diamond.active = false;
  133. // this.diamond.stopAllActions();
  134. // this.state = 0;
  135. // this.diamondEnds(tempCount);
  136. // }.bind(this);
  137. // this.scheduleOnce(this.callbackstop, 0.5);
  138. this.diamond.active = false;
  139. this.state = 0;
  140. this.diamondEnds(tempCount);
  141. // this.callbackstop = function () {
  142. //
  143. // }.bind(this);
  144. // this.scheduleOnce(this.callbackstop, 0.5);
  145. task.taskZS();
  146. }.bind(this));
  147. var ScaleToAnim = cc.scaleTo(Duration, DiamondIcon.scale);
  148. var sequence = cc.sequence(cc.spawn(MoveAnim.easing(cc.easeOut(Duration)),ScaleToAnim), finished);
  149. this.diamond.runAction(sequence);
  150. },
  151. diamondEnds : function (count) {
  152. if (count >= this.diamondCount1 && count < this.diamondCount2) {
  153. GlobalD.GameData.PlusDiamond(10);
  154. }else if (count >= this.diamondCount2 && count < this.diamondCount3) {
  155. GlobalD.GameData.PlusDiamond(30);
  156. }else if (count>=this.diamondCount3) {
  157. GlobalD.GameData.PlusDiamond(50);
  158. }
  159. var tempNode = this.node;
  160. if (tempNode.getChildByName(this.diamond.name)!=null) {
  161. tempNode.getChildByName(this.diamond.name).destroy();
  162. }
  163. this._init();
  164. },
  165. /**
  166. * 得到一个节点的世界坐标
  167. * node的原点在中心
  168. * @param {*} node
  169. */
  170. localConvertWorldPointAR:function(node) {
  171. if (node) {
  172. return node.convertToWorldSpaceAR(cc.v2(0, 0));
  173. }
  174. return null;
  175. },
  176. /**
  177. * 得到一个节点的世界坐标
  178. * node的原点在左下边
  179. * @param {*} node
  180. */
  181. localConvertWorldPoint:function(node) {
  182. if (node) {
  183. return node.convertToWorldSpace(cc.v2(0, 0));
  184. }
  185. return null;
  186. },
  187. /**
  188. * 把一个世界坐标的点,转换到某个节点下的坐标
  189. * 原点在node中心
  190. * @param {*} node
  191. * @param {*} worldPoint
  192. */
  193. worldConvertLocalPointAR: function(node, worldPoint) {
  194. if (node) {
  195. return node.convertToNodeSpaceAR(worldPoint);
  196. }
  197. return null;
  198. },
  199. /**
  200. * 把一个世界坐标的点,转换到某个节点下的坐标
  201. * 原点在node左下角
  202. * @param {*} node
  203. * @param {*} worldPoint
  204. */
  205. worldConvertLocalPoint: function(node, worldPoint) {
  206. if (node) {
  207. return node.convertToNodeSpace(worldPoint);
  208. }
  209. return null;
  210. },
  211. /**
  212. * * 把一个节点的本地坐标转到另一个节点的本地坐标下
  213. * @param {*} node
  214. * @param {*} targetNode
  215. */
  216. convetOtherNodeSpace : function(node, targetNode) {
  217. if (!node || !targetNode) {
  218. return null;
  219. }
  220. //先转成世界坐标
  221. let worldPoint = this.localConvertWorldPoint(node);
  222. return this.worldConvertLocalPoint(targetNode, worldPoint);
  223. },
  224. /**
  225. * * 把一个节点的本地坐标转到另一个节点的本地坐标下
  226. * @param {*} node
  227. * @param {*} targetNode
  228. */
  229. convetOtherNodeSpaceAR: function(node, targetNode) {
  230. if (!node || !targetNode) {
  231. return null;
  232. }
  233. //先转成世界坐标
  234. let worldPoint = this.localConvertWorldPointAR(node);
  235. return this.worldConvertLocalPointAR(targetNode, worldPoint);
  236. },
  237. update (dt) {
  238. // this.setOpacity();
  239. },
  240. setOpacity : function(){
  241. if (this.diamond!=null) {
  242. if (this.Colortag) {
  243. if (this.diamond.opacity<=0) {
  244. this.Colortag = false;
  245. }else{
  246. this.diamond.opacity -=5;
  247. // console.log("都有什么 变了吗",this.coin);
  248. }
  249. }
  250. }
  251. },
  252. });