Charactor_javeLin.js 18 KB

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