var DWTool = require('../utils/DWTool'); const ArtistManager = require('../utils/ArtistManager'); var { UserJobType } = require('../utils/GameEnum'); cc.Class({ extends: cc.Component, properties: { figure: sp.Skeleton, //人物形象 decoration: sp.Skeleton, //人物配件动画 figureSprite: cc.Sprite, //人物静态图 }, // LIFE-CYCLE CALLBACKS: onLoad () { this.node.on('touchend', () => { this.figure.setAnimation(0, 'click', false); this.figure.setCompleteListener(() => { this.figure.setAnimation(0, 'stand', true); }); }, this); }, start () { }, hideFigure() { this.node.active = false; this.decoration.node.active = false; this.figure.node.active = false; this.figureSprite.node.active = false; }, onDisable() { this.hideFigure(); }, changeFigure(userInfo) { this.hideFigure(); this.userInfo = userInfo; //因骨骼动画未完成所有职业,故判断来读取静态图片 var isLoadImage = false; if (userInfo.jobId == 0) { isLoadImage = true; } if (isLoadImage) { this.changeFigureImage(); } else { ArtistManager.loadArtist(true, userInfo.gender, userInfo.jobId) .then((skeletonData) => { this.figure.skeletonData = skeletonData; this.figure.animation = "stand"; this.figure.node.active = true; this.node.active = true; this.configDecoration(); }).catch((error) => { }); } }, changeFigureImage() { ArtistManager.loadArtistImage(this.userInfo.gender, this.userInfo.jobId) .then((spriteFrame) => { this.figureSprite.spriteFrame = spriteFrame; this.figureSprite.node.active = true; this.node.active = true; }).catch((err) => { }); }, configDecoration() { var filePath = ''; var animation = ''; if (this.userInfo.gender == 2 && this.userInfo.jobId == UserJobType.Dancer) { filePath = 'people_spines/wuzhe_huaban'; animation = 'huaban'; } else if (this.userInfo.gender != 2 && this.userInfo.jobId == UserJobType.Singer) { filePath = 'people_spines/geshou_yinfu'; animation = 'yinfu'; } cc.loader.loadRes(filePath, sp.SkeletonData, (err, skeletonData,) => { if (err) { } else { this.decoration.skeletonData = skeletonData; this.decoration.animation = animation; this.decoration.node.active = true; } });s }, // update (dt) {}, });