2.0.9.p1 版本动态加载spine动画报错!!!

也是 没办法 回到2.0.8了

你2.0.8用的什么方法加载的?


export const createDragonBoneFromCDN = (
  dragonDisplay: dragonBones.ArmatureDisplay,
  dragonBonesAtlasAssetPath: string,
  dragonBonesAssetPath: string,
  playTime: number,
  randomPlay: boolean = false
) => {
  return new Promise((resolve, reject) => {

    const fishImageUrl: string = `${dragonBonesAtlasAssetPath}.png`
    const fishSkeUrl: string = `${dragonBonesAssetPath}.json`
    const fishAtlasUrl: string = `${dragonBonesAtlasAssetPath}.json`

    downloader.load({ url: fishImageUrl, type: 'png' }, (error, image) => {
      if (error) { reject(error) }

      downloader.load({ url: fishAtlasUrl, type: 'txt' }, (error, atlasJson) => {
        if (error) { reject(error) }

        downloader.load({ url: fishSkeUrl, type: 'txt' }, (error, dragonBonesJson) => {
          if (error) { reject(error) }

          const atlas = new dragonBones.DragonBonesAtlasAsset()
          atlas.atlasJson = atlasJson
          atlas.texture = image

          const asset = new dragonBones.DragonBonesAsset()
          asset.dragonBonesJson = dragonBonesJson

          dragonDisplay.dragonAtlasAsset = atlas
          dragonDisplay.dragonAsset = asset
          dragonDisplay.armatureName = 'armatureName'


              dragonDisplay.playAnimation('newAnimation', playTime)


          resolve('dragon load success')
        });
      });
    });
  })
}

关于动态加载json,spine或dragonbones无法显示的问题,
可以先这么处理

spine:
var asset = new sp.SkeletonData();
asset._uuid = url; // 这个url是这个json的url

dragonbones:
var atlas = new dragonBones.DragonBonesAtlasAsset();
atlas._uuid = atlasUrl; // 这个url是这个atlas的url
var asset = new dragonBones.DragonBonesAsset();
asset._uuid = asseturl; // 这个url是这个db json的url

本质上是因为手动new 的asset没有uuid造成的,因为新版本,用uuid作为key了,之前用动画的name作为key容易产生重名的问题,下个版本会兼容处理这种手动创建Asset的问题了。

目前 使用了动态加载spine 并且赋值了_uuid 但是 setAnimationCacheMode(sp.Skeleton.AnimationCacheMode.SHARED_CACHE);
还是有问题。显示不正确。

27分钟前
目前 使用了动态加载spine 并且赋值了_uuid 但是 setAnimationCacheMode(sp.Skeleton.AnimationCacheMode.SHARED_CACHE);
还是有问题。显示不正确。

麻烦贴下你创建spine的代码片段

var image = “D:/2d/skeleton.png”;
var ske = “D:/2d/skeleton.json”;
var atlas = “D:/2d/skeleton.atlas.txt”;

cc.loader.load(image, (error, texture) => {
    cc.log(error);
    cc.loader.load({ url: atlas, type: 'txt' }, (error, atlasJson) => {
        cc.log(error);
        cc.loader.load({ url: ske, type: 'txt' }, (error, spineJson) => {
            cc.log(error);
            cc.log("11111111111111")
            cc.log(atlasJson);
            cc.log(spineJson);
            cc.log("22222222222222")
            var asset = new sp.SkeletonData();
            asset.skeletonJson = spineJson;
            asset.atlasText = atlasJson;
            asset.name = "skeleton";
            asset["_uuid"]=ske;
            asset.textures = [texture];

            asset["textureNames"] = ['skeleton.png'];
            
            cc.log(asset);
            cc.log("333333333333")
            
            skeleton.skeletonData=asset;
        });
    });
});

if (this.loadobj.root_node)
{

        let spine = this.loadobj.root_node.getComponent(sp.Skeleton) as sp.Skeleton;
        let spine_data = new sp.SkeletonData();
        spine_data._uuid = json_url;
        spine_data.skeletonJson = spine_json;
        spine_data.atlasText = atlasJson;
        spine_data.name = texture_name;
        spine_data.textures = [texture];
        spine_data.textureNames = [texture_name];
        spine.setAnimationCacheMode(sp.Skeleton.AnimationCacheMode.SHARED_CACHE);
        spine.skeletonData = spine_data;



        //  spine.animation = "m1_idle_1";
        //spine.premultipliedAlpha = false;
        //spine.setAnimationCacheMode(sp.Skeleton.AnimationCacheMode.SHARED_CACHE);
     
       // cc.log(spine.isAnimationCached());
       
    }

不要沉, 我也这个问题报错. 给了uuid.
spine.skeletonData = spine_data;这里报错

spine动态加载的问题, 什么时候能解决呢? 好着急

报的什么错呢

有没有报错呢?

麻烦你发个demo吧,我这没法重现,或者加下我QQ 1053210246。

spineDemo.rar (1.2 MB)

修复代码,将在 2.0.10 登录 https://github.com/cocos-creator/engine/pull/4020

1赞

// If create by manual, uuid is empty.
this._uuid = this._uuid || value.skeleton.hash;
你们都不验证一下的吗,在新版本2.4.6中value传进来的是字符串,又不是json对象怎么获取skeleton字段。你们也太马虎了吧,还有就是二进制根本不能用,请修复!

···js
skeletonJson: {

        get: function () {

            return this._skeletonJson;

        },

        set: function (value) {

            this.reset();

            if (typeof(value) == "string") {

                this._skeletonJson = JSON.parse(value);

            } else {

                this._skeletonJson = value;

            }

            // If create by manual, uuid is empty.

            if (!this._uuid && value.skeleton) {

                this._uuid = value.skeleton.hash;

            }

        }

    },

···

修改为:
// If create by manual, uuid is empty.

            if (!this._uuid && this._skeletonJson.skeleton) {

                this._uuid = this._skeletonJson.skeleton.hash;

            }

@jare

2.4.6版本动态加载二进制spine,求解决