UserInformationFigure.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. var DWTool = require('../utils/DWTool');
  2. const ArtistManager = require('../utils/ArtistManager');
  3. var { UserJobType } = require('../utils/GameEnum');
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. figure: sp.Skeleton, //人物形象
  8. decoration: sp.Skeleton, //人物配件动画
  9. figureSprite: cc.Sprite, //人物静态图
  10. },
  11. // LIFE-CYCLE CALLBACKS:
  12. onLoad () {
  13. this.node.on('touchend', () => {
  14. this.figure.setAnimation(0, 'click', false);
  15. this.figure.setCompleteListener(() => {
  16. this.figure.setAnimation(0, 'stand', true);
  17. });
  18. }, this);
  19. },
  20. start () {
  21. },
  22. hideFigure() {
  23. this.node.active = false;
  24. this.decoration.node.active = false;
  25. this.figure.node.active = false;
  26. this.figureSprite.node.active = false;
  27. },
  28. onDisable() {
  29. this.hideFigure();
  30. },
  31. changeFigure(userInfo) {
  32. this.hideFigure();
  33. this.userInfo = userInfo;
  34. //因骨骼动画未完成所有职业,故判断来读取静态图片
  35. var isLoadImage = false;
  36. if (userInfo.jobId == 0) {
  37. isLoadImage = true;
  38. }
  39. if (isLoadImage) {
  40. this.changeFigureImage();
  41. } else {
  42. ArtistManager.loadArtist(true, userInfo.gender, userInfo.jobId)
  43. .then((skeletonData) => {
  44. this.figure.skeletonData = skeletonData;
  45. this.figure.animation = "stand";
  46. this.figure.node.active = true;
  47. this.node.active = true;
  48. this.configDecoration();
  49. }).catch((error) => {
  50. });
  51. }
  52. },
  53. changeFigureImage() {
  54. ArtistManager.loadArtistImage(this.userInfo.gender, this.userInfo.jobId)
  55. .then((spriteFrame) => {
  56. this.figureSprite.spriteFrame = spriteFrame;
  57. this.figureSprite.node.active = true;
  58. this.node.active = true;
  59. }).catch((err) => {
  60. });
  61. },
  62. configDecoration() {
  63. var filePath = '';
  64. var animation = '';
  65. if (this.userInfo.gender == 2 && this.userInfo.jobId == UserJobType.Dancer) {
  66. filePath = 'people_spines/wuzhe_huaban';
  67. animation = 'huaban';
  68. } else if (this.userInfo.gender != 2 && this.userInfo.jobId == UserJobType.Singer) {
  69. filePath = 'people_spines/geshou_yinfu';
  70. animation = 'yinfu';
  71. }
  72. cc.loader.loadRes(filePath, sp.SkeletonData, (err, skeletonData,) => {
  73. if (err) {
  74. } else {
  75. this.decoration.skeletonData = skeletonData;
  76. this.decoration.animation = animation;
  77. this.decoration.node.active = true;
  78. }
  79. });s
  80. },
  81. // update (dt) {},
  82. });