上次是loadRes,然后传入dragonBones.DragonBonesAsset 和 dragonBones.DragonBonesAtlasAsset等类型就没问题了,但是现在我要把这些动态资源直接放到服务器上,需要使用load的方式加载外部资源,需要怎么配置才能加载成功呢?
远程加载龙骨动画参考下列代码:
if (cc.find('Canvas/animNode')) {
cc.find('Canvas/animNode').destroy();
}
else {
var animNode = new cc.Node();
animNode.name = 'animNode';
animNode.parent = cc.find('Canvas');
var dragonDisplay = animNode.addComponent(dragonBones.ArmatureDisplay);
var image = 'http://127.0.0.1:5500/assets/resources/Monster/monsterbone001_0_tex.png';
var ske = 'http://127.0.0.1:5500/assets/resources/Monster/monsterbone001_0_ske.json';
var atlas = 'http://127.0.0.1:5500/assets/resources/Monster/monsterbone001_0_tex.json';
cc.loader.load(image, (error, texture) => {
cc.loader.load({ url: atlas, type: 'txt' }, (error, atlasJson) => {
cc.loader.load({ url: ske, type: 'txt' }, (error, dragonBonesJson) => {
var atlas = new dragonBones.DragonBonesAtlasAsset();
atlas.atlasJson = atlasJson;
atlas.texture = texture;
var asset = new dragonBones.DragonBonesAsset();
asset.dragonBonesJson = dragonBonesJson;
dragonDisplay.dragonAtlasAsset = atlas;
dragonDisplay.dragonAsset = asset;
dragonDisplay.armatureName = 'armatureName';
dragonDisplay.playAnimation('walk', 0);
});
});
});
}
}
测视例:https://github.com/Jno1995/dragonBone-spine_Dome/commits/master
1赞