9dc9611c-f29e-45d6-993e-c02e4ee32f74.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. "use strict";
  2. cc._RF.push(module, '9dc96Ec8p5F1pk+wC5O4y90', 'ani');
  3. // scripts/Game/ani.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var CocosZ_1 = require("../Framework/CocosZ");
  26. var gameDate_1 = require("./gameDate");
  27. var weapon_1 = require("./weapon");
  28. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, executeInEditMode = _a.executeInEditMode, playOnFocus = _a.playOnFocus;
  29. var Ani = /** @class */ (function (_super) {
  30. __extends(Ani, _super);
  31. function Ani() {
  32. var _this = _super !== null && _super.apply(this, arguments) || this;
  33. _this.times = 10;
  34. _this.aniNodeArr = [];
  35. _this._btnAdd = false;
  36. _this._btnStop = false;
  37. _this._btnDaiji = false;
  38. _this._btnRun = false;
  39. _this._btnAtk = false;
  40. _this._btnAtk2 = false;
  41. _this._btnDeath = false;
  42. _this.handLeft = null;
  43. _this.body = null;
  44. _this.leg = null;
  45. _this.handRight = null;
  46. _this.head = null;
  47. _this.weapon = null;
  48. _this.aniNode = null; //动画节点
  49. _this._t = 0; //计时
  50. _this._index = 0; //动画帧
  51. _this._isLoop = false; //是否循环
  52. _this._aniArr = []; //动画数组
  53. return _this;
  54. }
  55. Object.defineProperty(Ani.prototype, "btnAdd", {
  56. get: function () { return this._btnAdd; },
  57. set: function (v) {
  58. var _this = this;
  59. this.aniNodeArr = [];
  60. this.node.children.forEach(function (n) { _this.aniNodeArr.push(n); });
  61. },
  62. enumerable: false,
  63. configurable: true
  64. });
  65. Object.defineProperty(Ani.prototype, "btnStop", {
  66. get: function () { return this._btnStop; },
  67. set: function (v) {
  68. this._btnStop = false;
  69. this.stopAni();
  70. this.aniNodeArr.forEach(function (node) { node.opacity = 255; }, null);
  71. },
  72. enumerable: false,
  73. configurable: true
  74. });
  75. Object.defineProperty(Ani.prototype, "btnDaiji", {
  76. get: function () { return this._btnDaiji; },
  77. set: function (v) {
  78. this._btnDaiji = false;
  79. this.addAni("daiji", false);
  80. },
  81. enumerable: false,
  82. configurable: true
  83. });
  84. Object.defineProperty(Ani.prototype, "btnRun", {
  85. get: function () { return this._btnRun; },
  86. set: function (v) {
  87. this._btnRun = false;
  88. this.addAni("run", false);
  89. },
  90. enumerable: false,
  91. configurable: true
  92. });
  93. Object.defineProperty(Ani.prototype, "btnAtk", {
  94. get: function () { return this._btnAtk; },
  95. set: function (v) {
  96. this._btnAtk = false;
  97. this.addAni("atk", false);
  98. },
  99. enumerable: false,
  100. configurable: true
  101. });
  102. Object.defineProperty(Ani.prototype, "btnAtk2", {
  103. get: function () { return this._btnAtk2; },
  104. set: function (v) {
  105. this._btnAtk2 = false;
  106. this.addAni("atk2", false);
  107. },
  108. enumerable: false,
  109. configurable: true
  110. });
  111. Object.defineProperty(Ani.prototype, "btnDeath", {
  112. get: function () { return this._btnAtk2; },
  113. set: function (v) {
  114. this._btnDeath = false;
  115. this.addAni("death", false);
  116. },
  117. enumerable: false,
  118. configurable: true
  119. });
  120. Ani.prototype.onLoad = function () {
  121. this.handLeft = cc.find("handLeft", this.node);
  122. this.body = cc.find("body", this.node);
  123. this.leg = cc.find("leg", this.node);
  124. this.handRight = cc.find("handRight", this.node);
  125. this.head = cc.find("head", this.node);
  126. this.weapon = cc.find("weapon", this.node);
  127. };
  128. Ani.prototype.start = function () { };
  129. /**
  130. * 设置动画
  131. * @param name 动画名
  132. * @param isLoop 是否循环
  133. * @param time 动画间隔
  134. */
  135. Ani.prototype.setAni = function (name, isLoop) {
  136. if (isLoop === void 0) { isLoop = false; }
  137. // 清空动画数组
  138. this._aniArr = [];
  139. // 播放动画
  140. this.playAni(name, isLoop);
  141. };
  142. /**
  143. * 添加动画
  144. * @param name 动画名
  145. * @param isLoop 是否循环
  146. * @param time 动画间隔
  147. */
  148. Ani.prototype.addAni = function (name, isLoop) {
  149. if (this.aniNode) {
  150. this._aniArr.push({
  151. name: name,
  152. isLoop: isLoop,
  153. });
  154. }
  155. else {
  156. // 播放动画
  157. this.playAni(name, isLoop);
  158. }
  159. };
  160. /** 停止动画 */
  161. Ani.prototype.stopAni = function () {
  162. // 清空动画数组
  163. this._aniArr = [];
  164. // 停止动画
  165. this.aniNode = null;
  166. };
  167. /** 是否包含动画 */
  168. Ani.prototype.includeAni = function (name) {
  169. var r = false;
  170. this.aniNodeArr.forEach(function (n) {
  171. if (n.name == name)
  172. r = true;
  173. });
  174. return r;
  175. };
  176. /** 是否正在播放 */
  177. Ani.prototype.isAni = function (name) {
  178. if (this.aniNode && ((!name) || (name && this.aniNode.name.includes(name)))) {
  179. return true;
  180. }
  181. else {
  182. return false;
  183. }
  184. };
  185. Ani.prototype.playAni = function (name, isLoop) {
  186. var _this = this;
  187. if (isLoop === void 0) { isLoop = false; }
  188. this.aniNode = null;
  189. this._index = 0;
  190. this._t = 0;
  191. // 隐藏其它动画
  192. this.aniNodeArr.forEach(function (child) {
  193. if (child.name == name) {
  194. // child.active = true;
  195. child.active = true;
  196. child.opacity = 255;
  197. _this.aniNode = child;
  198. }
  199. else {
  200. // child.active = false;
  201. child.active = true;
  202. child.opacity = 0;
  203. }
  204. });
  205. // 循环播放
  206. this._isLoop = isLoop;
  207. // 输出
  208. if (this.aniNode) {
  209. // cc.log("播放动画:", name);
  210. }
  211. else {
  212. cc.log("动画不存在:" + name);
  213. }
  214. };
  215. Ani.prototype.lateUpdate = function () {
  216. var _this = this;
  217. if (this.aniNode && this.aniNode.isValid) {
  218. if (this._t % this.times == 0) {
  219. this._t = 0;
  220. // 切换图片
  221. this.aniNode.children.forEach(function (child, index) {
  222. if (index == _this._index) {
  223. child.opacity = 255;
  224. }
  225. else {
  226. child.opacity = 0;
  227. }
  228. });
  229. // 动画帧++
  230. this._index++;
  231. // 判断动画
  232. if (this._index >= this.aniNode.childrenCount) {
  233. if (this._isLoop) {
  234. // 循环的当前动画
  235. this._index = 0;
  236. }
  237. else if (this._aniArr.length > 0) {
  238. // 下一个动画
  239. var json = this._aniArr.shift();
  240. this.playAni(json.name, json.isLoop);
  241. }
  242. else {
  243. // 结束动画
  244. this.aniNode = null;
  245. this._index = 0;
  246. }
  247. }
  248. }
  249. // 帧自增
  250. this._t++;
  251. }
  252. };
  253. Ani.prototype.setSkinById = function (id) {
  254. this.setSkinByName((id + 1).toString());
  255. this.setGh(id);
  256. };
  257. Ani.prototype.setSkinByName = function (name) {
  258. this.head.children.forEach(function (child) {
  259. if (child.name == name) {
  260. child.active = true;
  261. child.opacity = 255;
  262. }
  263. else {
  264. // child.active = false;
  265. child.active = true;
  266. child.opacity = 0;
  267. }
  268. });
  269. };
  270. Ani.prototype.setWeaponById = function (id) {
  271. this.setWeaponByName(weapon_1.default.WeaponName[id]);
  272. this.setSD(id);
  273. };
  274. Ani.prototype.setWeaponByName = function (name) {
  275. if (gameDate_1.default.Weapon[name].atkRange > 300) {
  276. this.weapon.active = true;
  277. this.handLeft.active = false;
  278. this.handRight.active = false;
  279. var pre = CocosZ_1.cocosz.resMgr.getRes("weapon_" + name, cc.Prefab);
  280. if (pre) {
  281. var rangeWeapon = cc.instantiate(pre);
  282. rangeWeapon.removeComponent(weapon_1.default);
  283. this.weapon.children[0] && this.weapon.children[0].isValid && this.weapon.children[0].destroy();
  284. this.weapon.addChild(rangeWeapon);
  285. }
  286. }
  287. else {
  288. this.weapon.active = false;
  289. this.handLeft.active = true;
  290. this.handRight.active = true;
  291. var pre = CocosZ_1.cocosz.resMgr.getRes("weapon_" + name, cc.Prefab);
  292. if (pre) {
  293. var meleeWeapon = cc.instantiate(pre);
  294. meleeWeapon.removeComponent(weapon_1.default);
  295. this.handRight.children[0] && this.handRight.children[0].isValid && this.handRight.children[0].destroy();
  296. this.handRight.addChild(meleeWeapon);
  297. }
  298. }
  299. };
  300. /** 显示光环 */
  301. Ani.prototype.setGh = function (id) {
  302. var gh = this.node.getChildByName("gh");
  303. if (gh && gh.isValid) {
  304. var info = CocosZ_1.cocosz.dataMgr.getSkinInfo(id);
  305. if (info) {
  306. var ghAni = gh.getComponent(sp.Skeleton);
  307. gh.active = true;
  308. if (ghAni && ghAni.isValid) {
  309. var personLevel = info.Level;
  310. if (personLevel > 0) {
  311. gh.color = cc.Color.WHITE;
  312. var arr = ["", "y", "p", "r"];
  313. ghAni.setSkin(arr[Math.ceil(personLevel / 2)]);
  314. ghAni.setAnimation(0, "animation", true);
  315. }
  316. else {
  317. gh.color = cc.Color.BLACK;
  318. ghAni.setSkin("r");
  319. ghAni.setAnimation(0, "animation", true);
  320. }
  321. }
  322. }
  323. }
  324. };
  325. /** 显示闪电 */
  326. Ani.prototype.setSD = function (id) {
  327. var info = CocosZ_1.cocosz.dataMgr.getGunInfo(id);
  328. this.node.walk(function (child) {
  329. if (child.name == "sd") {
  330. if (info.Level > 0) {
  331. child.active = true;
  332. var spAni = child.getComponent(sp.Skeleton);
  333. if (spAni) {
  334. var arr = ["", "y", "p", "r"];
  335. spAni && spAni.setSkin(arr[info.Level]);
  336. }
  337. }
  338. else {
  339. child.active = false;
  340. }
  341. }
  342. }, null);
  343. };
  344. __decorate([
  345. property({ displayName: "间隔帧数" })
  346. ], Ani.prototype, "times", void 0);
  347. __decorate([
  348. property({ type: [cc.Node], displayName: "动画数组" })
  349. ], Ani.prototype, "aniNodeArr", void 0);
  350. __decorate([
  351. property()
  352. ], Ani.prototype, "_btnAdd", void 0);
  353. __decorate([
  354. property({ displayName: "添加动画" })
  355. ], Ani.prototype, "btnAdd", null);
  356. __decorate([
  357. property({ displayName: "停止动画" })
  358. ], Ani.prototype, "_btnStop", void 0);
  359. __decorate([
  360. property
  361. ], Ani.prototype, "btnStop", null);
  362. __decorate([
  363. property({ displayName: "待机动画" })
  364. ], Ani.prototype, "_btnDaiji", void 0);
  365. __decorate([
  366. property
  367. ], Ani.prototype, "btnDaiji", null);
  368. __decorate([
  369. property({ displayName: "跑步动画" })
  370. ], Ani.prototype, "_btnRun", void 0);
  371. __decorate([
  372. property
  373. ], Ani.prototype, "btnRun", null);
  374. __decorate([
  375. property({ displayName: "攻击动画" })
  376. ], Ani.prototype, "_btnAtk", void 0);
  377. __decorate([
  378. property
  379. ], Ani.prototype, "btnAtk", null);
  380. __decorate([
  381. property({ displayName: "攻击动画2" })
  382. ], Ani.prototype, "_btnAtk2", void 0);
  383. __decorate([
  384. property
  385. ], Ani.prototype, "btnAtk2", null);
  386. __decorate([
  387. property({ displayName: "死亡动画2" })
  388. ], Ani.prototype, "_btnDeath", void 0);
  389. __decorate([
  390. property
  391. ], Ani.prototype, "btnDeath", null);
  392. Ani = __decorate([
  393. ccclass,
  394. executeInEditMode,
  395. playOnFocus
  396. ], Ani);
  397. return Ani;
  398. }(cc.Component));
  399. exports.default = Ani;
  400. cc._RF.pop();