
protected _textures: Texture2D[] = [];
/**
* 加载远程spine文件
* @param spineItem spine文件Url信息
* @param completeHD
*/
public async wwwLoadSpine(spineItem: ResLoaderSpineItem, completeHD: Function) {
let ske = spineItem.url_json;
let atlas = spineItem.url_atlas;
//多个png
let png_names = this.getLastPartOfUrls(spineItem.url_png);
await this.wwwLoadImages(spineItem.url_png);
await assetManager.loadAny([{ url: atlas, ext: '.atlas' }, { url: ske, ext: '.json' }], (error, assets) => {
if (error) {
console.error("load error spine json path " + ske);
}
//多个png
let asset = new sp.SkeletonData();
asset.skeletonJson = assets[1];
asset.atlasText = assets[0];
asset.textures = this._textures;
asset.textureNames = png_names;
completeHD(asset);
});
}
//返回url最后一个/后的内容
protected getLastPartOfUrls(urls: string[]): string[] | null {
let matchStrs: string[] = [];
const regex = /[^/]+$/;
for (let i = 0; i < urls.length; i++) {
let url = urls[i];
const match = url.match(regex);
let matchStr = match ? match[0] : null;
if (matchStr != null) {
matchStrs.push(matchStr);
} else {
console.error("error spine url_name is null");
}
}
return matchStrs;
}
//加载远程图片组
public async wwwLoadImages(paths: string[]) {
//let textures: Texture2D[] = [];
return new Promise((resolve) => {
for (let i = 0; i < paths.length; i++) {
let image = paths[i];
assetManager.loadRemote(image, (error, img: ImageAsset) => {
if (error) {
console.error("load error spine path " + image);
return;
}
let texture = new Texture2D();
texture.image = img;
this._textures.push(texture);
if (i == paths.length - 1) {
resolve(texture);
}
});
}
})
}
这样加载的多个png的Spine出来是图片叠加在一起了,有大佬指点一下吗,要怎么加载
