diff --git a/packages/api/src/asset/IAssetManager.ts b/packages/api/src/asset/IAssetManager.ts index 6457e286..5005341c 100644 --- a/packages/api/src/asset/IAssetManager.ts +++ b/packages/api/src/asset/IAssetManager.ts @@ -12,6 +12,7 @@ export interface IAssetManager getAsset(name: string): IGraphicAsset; getCollection(name: string): IGraphicAssetCollection; createCollection(data: IAssetData, spritesheet: Spritesheet): IGraphicAssetCollection; + loadTextureFromUrl(url: string, name?: string): Promise downloadAssets(urls: string[]): Promise; downloadAsset(url: string): Promise; readonly collections: Map; diff --git a/packages/assets/src/AssetManager.ts b/packages/assets/src/AssetManager.ts index 06953fe7..4d2b40fb 100644 --- a/packages/assets/src/AssetManager.ts +++ b/packages/assets/src/AssetManager.ts @@ -74,6 +74,27 @@ export class AssetManager implements IAssetManager return collection; } + public async loadTextureFromUrl(url: string, name: string = null): Promise + { + if(!url || !url.length) return null; + + try + { + const texture = await Assets.load(url); + + if(!texture) return null; + + this.setTexture(name ?? url, texture); + + return texture; + } + + catch (err) + { + NitroLogger.error(err); + } + } + public async downloadAssets(urls: string[]): Promise { if(!urls || !urls.length) return Promise.resolve(true);