[Cocos Creator] 本地文件加載系列一:本地文件讀取(web模式)
[Cocos Creator] 本地文件加載系列二:本地音頻文件播放(web模式)
[Cocos Creator] 本地文件加載系列三:本地粒子文件加載和播放(web模式)
[Cocos Creator] 本地文件加載系列四:本地圖片文件加載(web模式)
[Cocos Creator] 本地文件加載系列五:本地spine文件加載(web模式)
// TS
// 方法參考前文
// dragonBone: dragonBones.ArmatureDisplay = null;
readLocalFile(dragonbonesFile, READ_FILE_TYPE.TEXT, (animResult: string | ArrayBuffer) => {
if (animResult && atlasFile) {
readLocalFile(atlasFile, READ_FILE_TYPE.TEXT, (atlasResult: string | ArrayBuffer) => {
if (atlasResult && imgFile) {
readLocalFile(imgFile, READ_FILE_TYPE.DATA_URL, (imgResult: string | ArrayBuffer) => {
if (imgResult) {
let fileBase64 = imgResult.toString();
base64ToTexture2D(fileBase64, (texture: cc.Texture2D) => {
let dragonAtlasAsset = new dragonBones.DragonBonesAtlasAsset();
dragonAtlasAsset.atlasJson = atlasResult.toString();
dragonAtlasAsset.texture = texture;
let dragonAsset = new dragonBones.DragonBonesAsset();
dragonAsset.dragonBonesJson = animResult.toString();
dragonBone.dragonAsset = dragonAsset;
dragonBone.dragonAtlasAsset = dragonAtlasAsset;
// 獲取所有動畫名
// let armatureNames = dragonBone.getArmatureNames();
let json = JSON.parse(dragonAsset.dragonBonesJson);
let armatures = json["armature"];
let armatureNames = [];
for (let i = 0; i < armatures.length; i++) {
armatureNames.push(armatures[i].name);
}
if (armatureNames.length > 0) {
let defaultArmatureName = armatureNames[0];
dragonBone.armatureName = defaultArmatureName;
// let animationNames = dragonBone.getAnimationNames(defaultArmatureName);
let defaultArmature = armatures[0];
let animations = defaultArmature.animation;
let animationNames = [];
for (let i = 0; i < animations.length; i++) {
animationNames.push(animations[i].name);
}
if (animationNames.length > 0) {
dragonBone.playAnimation(animationNames[0], 0);
}
}
});
}
});
}
});
}
});
不清楚的地方查看引擎代碼