Charactor_javeLin.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. const GameStatesStatic = require('GameStates');
  2. const PlayerState = require('PlayerState');
  3. var BarrierSuperClass = require("BarrierSuper");
  4. cc.Class({
  5. extends: BarrierSuperClass,
  6. properties: {
  7. readyRunTag: 0,
  8. //当前进行的项目
  9. type: 0,
  10. Canvas: {
  11. default: null,
  12. type: cc.Node
  13. },
  14. },
  15. onLoad: function () {
  16. // var self = this;
  17. // cc.eventManager.addListener({
  18. // event: cc.EventListener.TOUCH_ALL_AT_ONCE,
  19. // onTouchesBegan () {
  20. // self.toggleTimeScale();
  21. // }
  22. // }, this.node);
  23. },
  24. start: function () {
  25. var spine = this.spine = this.getComponent('sp.Skeleton');
  26. // cc.log("现在 播放 骨骼动画对象", spine);
  27. this._hasStop = true;
  28. // this.setType();
  29. this.initData();
  30. // cc.log(this.node.parent.name);
  31. if (this.node.parent.name == "javetemp_Hero") {
  32. var HeroControl = cc.find("Hero").getComponent("HeroControl");
  33. HeroControl.playAudioByName("JavelinFlying");//播放标枪飞的声音
  34. }
  35. // this.getSpeedLv();
  36. // cc.log("当前游戏", this.Canvas.getComponent("GameStates").CurrentProgress);
  37. // this.javelin();
  38. // this.spine.setAnimation(0, "langan", true);
  39. // this.walk();
  40. // .setStartListener()用来设置开始播放动画的事件监听。
  41. },
  42. setListener: function () {
  43. // var _armatureDisPlay = this.getComponent(dragonBones.ArmatureDisplay);
  44. // var spine = this.spine = this.getComponent('sp.Skeleton');
  45. var spine = this.spine = this.getComponent(dragonBones.ArmatureDisplay);
  46. // spine.setStartListener(function (trackEntry) {
  47. // var animationName = trackEntry.animation ? trackEntry.animation.name : "";
  48. // // cc.log("[track %s][animation %s] start.", trackEntry.trackIndex, animationName);
  49. // // cc.log("现在 播放 的动画名字是", animationName);
  50. //
  51. // if (animationName == this.arr[this.type][this.walkLv]) {
  52. // if (this.readyRunTag == 0) {
  53. // // cc.log("走着");
  54. // // this.player.getComponent("playerlinkagebg").readyRun(this.walkLv);
  55. // }
  56. // this.readyRunTag++;
  57. // // this._hasStop = false;
  58. // }
  59. // this.setStatus(animationName);
  60. // }.bind(this));
  61. // // .setInterruptListener()用来设置动画被打断的事件监听。
  62. // spine.setInterruptListener(function (trackEntry) {
  63. // var animationName = trackEntry.animation ? trackEntry.animation.name : "";
  64. // // cc.log("[track %s][animation %s] interrupt.", trackEntry.trackIndex, animationName);
  65. //
  66. // if (this.interruptListener != null) {
  67. // this.interruptListener(animationName);
  68. // // cc.log("现在 打断 的动画名字是", animationName);
  69. // // this.spine.timeScale = 1;
  70. // }
  71. // }.bind(this));
  72. // // .setEndListener()用来设置动画播放完后的事件监听。
  73. // spine.setEndListener(function (trackEntry) {
  74. // var animationName = trackEntry.animation ? trackEntry.animation.name : "";
  75. // // cc.log("[track %s][animation %s] end.", trackEntry.trackIndex, animationName);
  76. //
  77. // // cc.log("现在 停止 的动画名字是", animationName);
  78. // if (animationName == this.statusArr[6] || animationName == this.statusArr[5]) {
  79. //
  80. // // this._hasStop = true;
  81. // }
  82. // if (this.endListener != null) {
  83. //
  84. // this.endListener(animationName);
  85. // // this.spine.timeScale = 1;
  86. // }
  87. //
  88. //
  89. // }.bind(this));
  90. // // .setDisposeListener()用来设置动画将被销毁的事件监听。
  91. // spine.setDisposeListener(function (trackEntry) {
  92. //
  93. // var animationName = trackEntry.animation ? trackEntry.animation.name : "";
  94. // // cc.log("[track %s][animation %s] will be disposed.", trackEntry.trackIndex, animationName);
  95. // }.bind(this));
  96. // // .setCompleteListener用来设置动画播放一次循环结束后的事件监听。
  97. // spine.setCompleteListener(function (trackEntry, loopCount) {
  98. // var animationName = trackEntry.animation ? trackEntry.animation.name : "";
  99. // // if (animationName === 'attack') { //如果当前为射击状态,立马清除
  100. // // // .clearTrack(对应状态数字)清除出指定 track 的动画状态。
  101. // // this.spine.clearTrack(1);
  102. // // }
  103. // // cc.log("[track %s][animation %s] complete: %s", trackEntry.trackIndex, animationName, loopCount);
  104. // }.bind(this));
  105. // // .setEventListener()用来设置动画播放过程中帧事件的监听。
  106. // spine.setEventListener(function (trackEntry, event) {
  107. // var animationName = trackEntry.animation ? trackEntry.animation.name : "";
  108. // // cc.log("[track %s][animation %s] event: %s, %s, %s, %s", trackEntry.trackIndex, animationName, event.data.name, event.intValue, event.floatValue, event.stringValue);
  109. // }.bind(this));
  110. },
  111. initData: function () {
  112. //初始化 动作列表
  113. this.statusArr = [
  114. //0
  115. "none",
  116. //1
  117. "idle",
  118. //2
  119. "idle-run",
  120. //3
  121. "run-01",
  122. //4
  123. "run-02",
  124. //5
  125. "run-03",
  126. //6
  127. "run-04",
  128. //7
  129. "run-05",
  130. //8
  131. "hurdling_1",
  132. //9
  133. "hurdling_2",
  134. //10
  135. "longjump-01",
  136. //11
  137. "longjump-02",
  138. "bybike_1",
  139. "bybike_2",
  140. "bybike_3",
  141. "bybike_4",
  142. "bybike_5",
  143. "bybike_5bike",
  144. "bybike_5boy",
  145. "bybike_redy",
  146. "bybike_redy_bike",
  147. "bybike_redy_boy",
  148. "Biaoqiang01",
  149. "Biaoqiang02",
  150. "Biaoqiang03",
  151. "javelin_1",
  152. "javelin_2",
  153. "javelin_2a",
  154. "javelin_3",
  155. "javelin_3a",
  156. "javelin_4",
  157. "javelin_5",
  158. "javelin_redy"
  159. ];
  160. //todo 准备跑步动作
  161. this.statusArr_redyrun = [
  162. //0
  163. "idle",
  164. //1
  165. "idle-run",
  166. ];
  167. // Race:0,
  168. // Hurdle:1,
  169. // Javelin:2,
  170. // LongJump:3,
  171. // RideBike:4,
  172. this.arr = [];
  173. //todo 跑步动作
  174. this.statusArr_run = [
  175. //0
  176. "run-01",
  177. //1
  178. "run-02",
  179. //2
  180. "run-03",
  181. //3
  182. "run-05",
  183. //4
  184. "run-04",
  185. ];
  186. this.arr.push(this.statusArr_run);
  187. //todo 跳远
  188. var a = [];
  189. this.statusArr_longjump = a.concat(this.statusArr_run);
  190. //5
  191. this.statusArr_longjump.push("longjump-01");
  192. //6
  193. this.statusArr_longjump.push("longjump-02");
  194. this.arr.push(this.statusArr_longjump);
  195. //todo 跨栏
  196. a = [];
  197. this.statusArr_hurdling = a.concat(this.statusArr_run);
  198. //5
  199. this.statusArr_hurdling.push("hurdling_1");
  200. //6
  201. this.statusArr_hurdling.push("hurdling_2");
  202. this.arr.push(this.statusArr_hurdling);
  203. //todo 蹬三轮
  204. this.statusArr_bike = [
  205. //0
  206. "bybike_1",
  207. //1
  208. "bybike_2",
  209. //2
  210. "bybike_3",
  211. //3
  212. "bybike_4",
  213. //4
  214. "bybike_5",
  215. //5
  216. "bybike_5bike",
  217. //6
  218. "bybike_5boy",
  219. //7
  220. "bybike_redy",
  221. //8
  222. "bybike_redy_bike",
  223. //9
  224. "bybike_redy_boy",
  225. ];
  226. this.arr.push(this.statusArr_bike);
  227. //todo 标枪项目
  228. this.statusArr_javelin = [
  229. //0
  230. "javelin_1",
  231. //1
  232. "javelin_2",
  233. //2
  234. "javelin_2a",
  235. //3
  236. "javelin_3",
  237. //4
  238. "javelin_3a",
  239. //5
  240. "javelin_4",
  241. //6
  242. "javelin_5",
  243. //7
  244. "javelin_redy"
  245. ];
  246. this.arr.push(this.statusArr_javelin);
  247. // cc.log("所有动作", this.arr);
  248. //todo 标枪
  249. this.statusArr_biaoqiang = [
  250. "Biaoqiang",
  251. "Biaoqiang02",
  252. "Biaoqiang03",
  253. ];
  254. //初始化动作状态
  255. this.setStatus(this.statusArr[1]);
  256. //初始化跳跃状态
  257. // this.setJumpTag(0);
  258. //设置当前没有 任何加速 机会
  259. this.setMyTag(null);
  260. },
  261. setMyTag: function (obj) {
  262. this.myTag = obj;
  263. },
  264. idle: function () {
  265. this.spine.setAnimation(0, this.statusArr_redyrun[0], true);
  266. },
  267. walk: function () {
  268. // .setAnimation(trackIndex,name,loop)设置当前动画。队列中的任何的动画将被清除。返回一个 sp.spine.TrackEntry 对象。
  269. this.spine.setAnimation(0, this.statusArr[3], true);
  270. },
  271. readyRun: function () {
  272. // this.spine.setAnimation(0, this.statusArr_redyrun[0], false);
  273. // this.spine.addAnimation(0, this.statusArr_redyrun[1], false);
  274. this.spine.setAnimation(0, this.statusArr_run[0], true);
  275. //奔跑等级
  276. this.walkLv = 0;
  277. },
  278. stagger: function () {
  279. // cc.log("帅哦到了",this.arr[this.type][3]);
  280. // .setAnimation(trackIndex,name,loop)设置当前动画。队列中的任何的动画将被清除。返回一个 sp.spine.TrackEntry 对象。
  281. this.spine.setAnimation(0, this.arr[this.type][3], false);
  282. // this.setCurrentSpeed();
  283. },
  284. longjump: function () {
  285. // this.spine.timeScale = 1.5;
  286. this.spine.setAnimation(0, this.statusArr_longjump[5], false);
  287. setTimeout(function () {
  288. this.spine.setAnimation(0, this.statusArr_longjump[6], false);
  289. if (this.timeOutLongJumpListener != null) {
  290. this.timeOutLongJumpListener();
  291. }
  292. // this.spine.addAnimation(0, this.statusArr_longjump[this.walkLv], true,0.5);
  293. }.bind(this), 1000);
  294. setTimeout(function () {
  295. this.paused();
  296. }.bind(this), 1500);
  297. setTimeout(function () {
  298. this.paused();
  299. // this.setCurrentSpeed();
  300. }.bind(this), 2500);
  301. },
  302. timeOutLongJumpListener: function () {
  303. },
  304. setTimeOutLongJumpListener: function (timeOutLongJumpListener) {
  305. this.timeOutLongJumpListener = timeOutLongJumpListener;
  306. },
  307. longjump_stagger: function () {
  308. this.spine.setAnimation(0, this.statusArr_longjump[1], false);
  309. // this.setCurrentSpeed();
  310. },
  311. hurdling: function () {
  312. this.spine.setAnimation(0, this.statusArr_hurdling[5], false);
  313. this.spine.addAnimation(0, this.statusArr_hurdling[this.walkLv], true);
  314. // this.setCurrentSpeed();
  315. },
  316. hurdling_stagger: function () {
  317. this.spine.setAnimation(0, this.statusArr_hurdling[1], false);
  318. // this.setCurrentSpeed();
  319. },
  320. //单纯的停止
  321. stop: function () {
  322. // .clearTrack(对应状态数字)清除出指定 track 的动画状态。
  323. this.spine.clearTrack(0);
  324. this.setStatus(this.statusArr_redyrun[0]);
  325. },
  326. //调用一次 暂停 再调用 恢复
  327. paused: function () {
  328. // .clearTrack(对应状态数字)清除出指定 track 的动画状态。
  329. if (this.spine.paused) {
  330. this.spine.paused = false;
  331. } else {
  332. this.spine.paused = true;
  333. }
  334. },
  335. /**
  336. * 设置当前的运动状态
  337. * @param status
  338. */
  339. setStatus: function (status) {
  340. this.myStatus = status;
  341. // cc.log("设置当前播放动画是",status);
  342. // this.player.getComponent("playerlinkagebg").upDatawalkLv(this.walkLv);
  343. },
  344. //按屏幕了
  345. setOnTouchListener: function () {
  346. // this.jump();
  347. // this.toggleTimeScale();
  348. // cc.log("什么名字",this.spine.animation);
  349. // cc.log("当前游戏 按屏幕了", this.Canvas.getComponent("GameStates").CurrentProgress);
  350. if (this.spine.animation == this.statusArr_redyrun[0]) {
  351. switch (this.type) {
  352. case 0:
  353. this.readyRun();
  354. break;
  355. case 1:
  356. this.upBike();
  357. break;
  358. }
  359. return;
  360. }
  361. this.setType();
  362. if (this._hasStop) {
  363. // this.setCurrentSpeed();
  364. }
  365. },
  366. //todo 跨栏 跳跃
  367. setOnHurdlingListener: function () {
  368. this.setType();
  369. // if (this._hasStop) {
  370. // this.speedUp();
  371. // }
  372. this.hurdling();
  373. },
  374. //todo 跨栏 踉跄
  375. setOnHurdlingStaggerListener: function () {
  376. this.setType();
  377. this.hurdling_stagger();
  378. },
  379. //todo 跳远跳跃
  380. setOnLongJumpListener: function () {
  381. this.setType();
  382. // if (this._hasStop) {
  383. // this.speedUp();
  384. // }
  385. this.longjump();
  386. },
  387. //todo 跳远 踉跄
  388. setOnLongJumpStaggerListener: function () {
  389. this.setType();
  390. this.longjump_stagger();
  391. },
  392. //摔倒了
  393. setOnTripListener: function () {
  394. this.setType();
  395. // this.jump();
  396. // this.toggleTimeScale();
  397. this.stagger();
  398. // this.speedDown();
  399. //
  400. // this.upBike();
  401. },
  402. toggleTimeScale: function () {
  403. // .timeScale当前骨骼中所有动画的时间缩放率。
  404. if (this.spine.timeScale === 1.0) {
  405. this.spine.timeScale = 0.3;
  406. } else {
  407. this.spine.timeScale = 1.0;
  408. }
  409. },
  410. setEndListener: function (endListener) {
  411. this.endListener = endListener
  412. },
  413. endListener: function () {
  414. },
  415. setInterruptListener: function (interruptListener) {
  416. this.interruptListener = interruptListener
  417. },
  418. interruptListener: function () {
  419. },
  420. //todo 快上车 没时间解释了
  421. upBike: function () {
  422. this.setType();
  423. // this.spine.setAnimation(0, this.statusArr_run[0], false);
  424. this.spine.setAnimation(0, this.statusArr_bike[9], false);
  425. this.spine.addAnimation(0, this.statusArr_bike[0], true);
  426. // this.setStatus(this.statusArr[this.walkLv]);
  427. this.walkLv = 0;
  428. },
  429. //todo 快拿标枪 没时间解释了
  430. upJavelin: function () {
  431. this.setType();
  432. // this.spine.setAnimation(0, this.statusArr_run[0], false);
  433. this.spine.setAnimation(0, this.statusArr_javelin[0], true);
  434. this.walkLv = 0;
  435. // this.setStatus(this.statusArr[this.walkLv]);
  436. // this.setCurrentSpeed();
  437. },
  438. //todo 快扔标枪 没时间解释了
  439. upJavelin_go: function () {
  440. this.setType();
  441. // this.spine.setAnimation(0, this.statusArr_run[0], false);
  442. this.spine.setAnimation(0, this.statusArr_javelin[6], false);
  443. this.walkLv = 0;
  444. // this.setStatus(this.statusArr[this.walkLv]);
  445. // this.setCurrentSpeed();
  446. },
  447. //todo 标枪 没时间解释了
  448. javelin: function (data, starListener, endListener) {
  449. // var spine = this.spine = this.getComponent('sp.Skeleton');
  450. cc.log('.....................');
  451. this.initData();
  452. this.setListener();
  453. var actionBy = cc.jumpBy(data.duration, data.position, data.y, data.height, data.jumps);
  454. // var actionrotateBy = cc.rotateBy(data.duration,60);
  455. // this.node.runAction(actionrotateBy);
  456. //设置标枪动画
  457. // tPrefab.getChildByName("jave").getComponent('sp.Skeleton').timeScale = 1/(data.duration*0.3);
  458. this.spine.timeScale = 1 / (data.duration * 0.3);
  459. var start = cc.callFunc(function () {
  460. if (starListener != null) {
  461. // this.spine.timeScale = 0.2;
  462. starListener();
  463. }
  464. }.bind(this), this);
  465. var stop = cc.callFunc(function () {
  466. if (endListener != null) {
  467. endListener();
  468. // this.spine.timeScale = 1;
  469. }
  470. }.bind(this), this);
  471. var myAction = cc.sequence(start, actionBy, stop);
  472. this.node.runAction(myAction);
  473. // var anim = this.getComponent(cc.Animation);
  474. // cc.log("要播放动画",this.spine);
  475. // anim.play();
  476. // this.setType();
  477. // this.spine.setAnimation(0, this.statusArr_run[0], false);
  478. // this.spine.clearTrack();
  479. // this.spine.setAnimation(0, this.statusArr_biaoqiang[0], false);
  480. // this.spine.addAnimation(0, this.statusArr_biaoqiang[1], false);
  481. // this.spine.addAnimation(0, this.statusArr_biaoqiang[2], false);
  482. this.walkLv = 0;
  483. // this.setStatus(this.statusArr[this.walkLv]);
  484. // this.setCurrentSpeed();
  485. // var spine2 = this.getComponent(dragonBones.ArmatureDisplay)
  486. // spine2.armatureName = 'Jav';
  487. // spine2.playAnimation('JavFly', 0);
  488. // cc.log('animationName is ');
  489. },
  490. setType: function () {
  491. var temp = this.Canvas.getComponent("GameStates").CurrentProgress;
  492. switch (temp) {
  493. case GameStatesStatic.GameProgress.Race:
  494. this.type = 0;
  495. // cc.log("当前的typssssse","s1");
  496. break;
  497. case GameStatesStatic.GameProgress.LongJump:
  498. this.type = 1;
  499. // cc.log("当前的typssssse","s2");
  500. break;
  501. case GameStatesStatic.GameProgress.Hurdle:
  502. this.type = 2;
  503. // cc.log("当前的typssssse","s3");
  504. break;
  505. case GameStatesStatic.GameProgress.RideBike:
  506. this.type = 3;
  507. // cc.log("当前的typssssse","s4");
  508. break;
  509. case GameStatesStatic.GameProgress.Javelin:
  510. this.type = 4;
  511. // cc.log("当前的typssssse","s5");
  512. break;
  513. }
  514. },
  515. getSpeedLv: function () {
  516. var lv = this.Canvas.getComponent("NodeTouch").Hero.getComponent("HeroControl").PlayerStateScript.CurrentSpeed;
  517. // PlayerState.SlowSpeed
  518. // PlayerState.MiddleSpeed
  519. // PlayerState.HightSpeed
  520. // cc.log("现在是什么啊",PlayerState);
  521. // cc.log("当前速度",lv);
  522. var state = PlayerState.SpeedRangeForAnimation;
  523. if (lv >= state.SlowSpeed[0] && lv <= state.SlowSpeed[1]) {
  524. return 0;
  525. }
  526. if (lv >= state.MiddleSpeed[0] && lv <= state.MiddleSpeed[1]) {
  527. return 1;
  528. }
  529. if (lv >= state.HightSpeed[0] && lv <= state.HightSpeed[1]) {
  530. return 2;
  531. }
  532. return 0;
  533. }
  534. // start () {
  535. //
  536. // },
  537. // update (dt) {},
  538. });