白鹭龙骨异步加载

private armatureDisplay: dragonBones.EgretArmatureDisplay;
/**
* 加载龙骨动画
* Create scene interface
*/
private loadGragon(): void {
let t = this;
t.removeGragon();
//默认男战士
let sex = t.occupationSex.selectedValue ? t.occupationSex.selectedValue : 1;
let url1 = `resource/assets/gameui2/dragon/${sex == 1 ? "nan" : "nv"}zhanshi_ske.json`;
let url2 = `resource/assets/gameui2/dragon/${sex == 1 ? "nan" : "nv"}zhanshi_tex.json`;
let url3 = `resource/assets/gameui2/dragon/${sex == 1 ? "nan" : "nv"}zhanshi_tex.png`;
RES.getResByUrl(url1, t.createGragon, t, RES.NOCache);
RES.getResByUrl(url2, t.createGragon, t, RES.NOCache);
RES.getResByUrl(url3, t.createGragon, t, RES.NOCache);

}
dragonbonesData;
textureData;
texture;
temp = 0;
/**
* 创建龙骨动画
* Create scene interface
*/
private createGragon(data, url): void {
let t = this;
if (data.frameRate) {
t.dragonbonesData = data;
} else if (data.SubTexture) {
t.textureData = data;
} else if (data.bitmapData) {
t.texture = data;
}
if (t.temp == 0) {
t.temp++;
} else if (t.temp == 1) {
t.temp++;
} else if (t.temp == 2 && t.texture && t.textureData && t.dragonbonesData) {
t.temp = 0;
let egretFactory: dragonBones.EgretFactory = dragonBones.EgretFactory.factory;
if (!t.dragonbonesData) return;
egretFactory.parseDragonBonesData(t.dragonbonesData);
egretFactory.parseTextureAtlasData(t.textureData, t.texture);
let sex = t.occupationSex.selectedValue ? t.occupationSex.selectedValue : 1;
t.armatureDisplay = sex == 1 ? egretFactory.buildArmatureDisplay("armatureName") : egretFactory.buildArmatureDisplay("nvzhanshi");

t.armatureDisplay.x = sex == 1 ? 550 : 580;
t.armatureDisplay.y = sex == 1 ? 480 : 280;
t.armatureDisplay.scaleX = 0.5;
t.armatureDisplay.scaleY = 0.5;
t.armatureDisplay.animation.play("animation", 0);
t.mainGro.addChildAt(t.armatureDisplay, 2);
}
}

private removeGragon(): void {
let t = this;
if (t.armatureDisplay) {
t.armatureDisplay.animation.stop();
t.armatureDisplay.dispose();
t.armatureDisplay.removeSelf();
t.armatureDisplay = null;
}
}

/**适用类似创角界面这种用一次龙骨的界面,经常使用的,不用这么麻烦,直接按官网的教程做就行**/

猜你喜欢

转载自www.cnblogs.com/jiajunjie/p/10922142.html