123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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) {},
- });
|