FruitItem.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. var Global = require("Global");
  2. var GameProtocol = require("FruitGameProtocol");
  3. var LBItem = require("LBItem");
  4. const itemConfig = {
  5. "1": { //单个
  6. //框
  7. kw: 200,
  8. kh: 190,
  9. kx: -2,
  10. //遮罩
  11. mw: 168,
  12. mh: 142,
  13. mx: 14,
  14. my: -22,
  15. sx: 86,
  16. sy: -216,
  17. //动画
  18. bw: 168,
  19. bh: 182,
  20. bx: 14,
  21. by: 16,
  22. ax: 111,
  23. ay: -162
  24. },
  25. "2": { //两个
  26. //框
  27. kw: 200,
  28. kh: 339,
  29. kx: -2,
  30. //遮罩
  31. mw: 168,
  32. mh: 288,
  33. mx: 14,
  34. my: -22,
  35. sx: 86,
  36. sy: -216,
  37. //动画
  38. bw: 168,
  39. bh: 288,
  40. bx: 14,
  41. by: -22,
  42. ax: 111,
  43. ay: -169
  44. },
  45. "3": { //三个
  46. //框
  47. kw: 200,
  48. kh: 490,
  49. kx: -2,
  50. //遮罩
  51. mw: 168,
  52. mh: 440,
  53. mx: 14,
  54. my: -22,
  55. sx: 86,
  56. sy: -216,
  57. //动画
  58. bw: 168,
  59. bh: 440,
  60. bx: 14,
  61. by: -22,
  62. ax: 111,
  63. ay: -169
  64. },
  65. "6": { //六个
  66. //框
  67. kw: 423,
  68. kh: 490,
  69. kx: -7,
  70. //遮罩
  71. mw: 379,
  72. mh: 440,
  73. mx: 14,
  74. my: -22,
  75. sx: 200,
  76. sy: -216,
  77. //动画
  78. bw: 379,
  79. bh: 440,
  80. bx: 14,
  81. by: -22,
  82. ax: 200,
  83. ay: -169
  84. }
  85. }
  86. cc.Class({
  87. extends: LBItem,
  88. editor: {
  89. menu: 'Game/Fruit/Item'
  90. },
  91. properties: {
  92. //特殊节点
  93. spNode: cc.Node,
  94. spAni: sp.Skeleton,
  95. kuang: cc.Node,
  96. mask: cc.Node,
  97. maskB: cc.Node,
  98. maskH: cc.Node,
  99. bAni: sp.Skeleton,
  100. hAni: sp.Skeleton,
  101. _bBig: false,
  102. _totalCount: 0,
  103. config: null,
  104. },
  105. // LIFE-CYCLE CALLBACKS:
  106. // onLoad () {
  107. // },
  108. setValue (_val, spineData, _bSpe) {
  109. this._bBig = _val == GameProtocol.MAN_ICON || _val == GameProtocol.WOMAN_ICON;
  110. this.normalBG.active = !this._bBig;
  111. this.spNode.active = this._bBig;
  112. this.spAni.skeletonData = spineData;
  113. this._super(_val, spineData, _bSpe);
  114. },
  115. setRowCount(_count) {
  116. this._totalCount = _count;
  117. this.config = null;
  118. this.node.active = _count >= 0;
  119. this.config = itemConfig[_count];
  120. this.setBigAniConfig();
  121. if(_count > 1) {
  122. // this.spAni.clearTracks();
  123. this.spAni.setAnimation(0, "a2", true);
  124. let name = "a2";
  125. if(this._value == GameProtocol.WOMAN_ICON) {
  126. name = "b2";
  127. }
  128. // this.bAni.clearTracks();
  129. this.bAni.setAnimation(0, name, true);
  130. // this.hAni.clearTracks();
  131. this.hAni.setAnimation(0, "c1", true);
  132. }
  133. },
  134. setBigAniConfig() {
  135. if(!this.config) return;
  136. this.spAni.node.x = this.config.sx;
  137. this.spAni.node.y = this.config.sy;
  138. if(this._value == GameProtocol.WOMAN_ICON) {
  139. this.spAni.node.x = this.config.ax;
  140. this.spAni.node.y = this.config.ay;
  141. }
  142. //框
  143. this.kuang.width = this.config.kw;
  144. this.kuang.height = this.config.kh;
  145. this.kuang.x = this.config.kx;
  146. //任务动画遮罩
  147. this.mask.width = this.config.bw;
  148. this.mask.height = this.config.bh;
  149. this.mask.x = this.config.bx;
  150. this.mask.y = this.config.by;
  151. //背景遮罩
  152. this.maskB.width = this.config.mw;
  153. this.maskB.height = this.config.mh;
  154. this.maskB.x = this.config.mx;
  155. this.maskB.y = this.config.my;
  156. //花瓣遮罩
  157. this.maskH.width = this.config.mw;
  158. this.maskH.height = this.config.mh;
  159. this.maskH.x = this.config.mx;
  160. this.maskH.y = this.config.my;
  161. this.bAni.node.x = this.config.sx;
  162. this.bAni.node.y = this.config.sy;
  163. this.hAni.node.x = this.config.sx;
  164. this.hAni.node.y = this.config.sy;
  165. // this.spAni.clearTracks();
  166. // this.spAni.setAnimation(0, "a2", true);
  167. },
  168. showAppearAction() {
  169. if(this._totalCount < 2) {
  170. return;
  171. }
  172. this.spNode.stopAllActions();
  173. this.spNode.scale = 0;
  174. cc.tween(this.spNode)
  175. .to(0.3, {scale: 1})
  176. .start()
  177. },
  178. resetShow() {
  179. if(this._totalCount > 1 || this._totalCount < 0) {
  180. return;
  181. }
  182. this.showNormal();
  183. },
  184. showNormal() {
  185. this.normalBG.stopAllActions();
  186. this.normalBG.scale = 1;
  187. this.aniNode.active = false;
  188. // this.normalAni.clearTracks();
  189. this.normalAni.setAnimation(0, "a1", true);
  190. if(this._bBig) {
  191. this.showBigSingle();
  192. }
  193. },
  194. showBigSingle() {
  195. //动画
  196. // this.spAni.clearTracks();
  197. this.spAni.setAnimation(0, "a1", true);
  198. let name = "a1";
  199. if(this._value == GameProtocol.WOMAN_ICON) {
  200. name = "b1";
  201. }
  202. // this.bAni.clearTracks();
  203. this.bAni.setAnimation(0, name, true);
  204. // this.hAni.clearTracks();
  205. this.hAni.setAnimation(0, "c1", true);
  206. this.config = itemConfig[1];
  207. this.setBigAniConfig();
  208. },
  209. showLightAni() {
  210. if(this._totalCount > 1) {
  211. return;
  212. }
  213. if(this._lineCount <= 0) {
  214. this.showNormal();
  215. return;
  216. }
  217. this.aniNode.active = false;
  218. this.normalBG.stopAllActions();
  219. // this.normalAni.clearTracks();
  220. this.normalAni.setAnimation(0, "a2", true);
  221. // this.spAni.clearTracks();
  222. this.spAni.setAnimation(0, "a2", true);
  223. },
  224. showSpecialAni() {
  225. if(!this._bSpecial) {
  226. // this.showNormal();
  227. return;
  228. }
  229. this.normalBG.stopAllActions();
  230. // this.normalAni.clearTracks();
  231. this.normalAni.setAnimation(0, "a2", true);
  232. // this.spAni.clearTracks();
  233. this.spAni.setAnimation(0, "a2", true);
  234. },
  235. // update (dt) {},
  236. });