@flare-engine/资产
明确驱动的资产装载 - AssetManager 有了进步信号, SpriteSheet (TexturePacker hash + 数组,Aseprite JSON),,"活塞活塞","活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活塞活, Texture 包起来 SkImage, (中文(简体) ), createProceduralAtlas 用于生成形状图集/占位符。 音频缓冲类型 @flare-engine/audio。 。 。 .
安装
bun add @flare-engine/assets
使用量
清单是 { key, type, path } 条目. AssetManager 代表
实际获取+解码到已插入的 AssetLoader;两艘默认装载船——
1个用于网络(fetch)和一个原生(文件系统) readFile) (中文(简体) ). 都拿一个
decodeImage 接通你的Skia/CanvasKit实例 所以包裹拉入
没有自己的制造者.
网络( CanvasKit)
import { AssetManager, createFetchAssetLoader, type ManifestEntry, type SkImageLike } from '@flare-engine/assets';
declare const kit: { MakeImageFromEncoded(bytes: Uint8Array): SkImageLike | null };
const loader = createFetchAssetLoader({
decodeImage: (bytes) => kit.MakeImageFromEncoded(bytes),
});
const manifest: ManifestEntry[] = [
{ key: 'hero', type: 'texture', path: '/assets/hero.png' },
{ key: 'atlas', type: 'spritesheet', path: '/assets/hero.json' },
];
const assets = new AssetManager(loader);
assets.onProgress.add((p) => console.log(`loading ${Math.round(p * 100)}%`));
await assets.load(manifest);
const hero = assets.get('hero'); // Texture
原生( 反应原生 + Skia)
import { Skia } from '@shopify/react-native-skia';
import * as FileSystem from 'expo-file-system';
import { AssetManager, createFileAssetLoader, decodeImage } from '@flare-engine/assets';
const loader = createFileAssetLoader({
readFile: async (path) => {
const base64 = await FileSystem.readAsStringAsync(path, {
encoding: FileSystem.EncodingType.Base64,
});
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
},
decodeImage: (bytes) => decodeImage(Skia, bytes),
});
const assets = new AssetManager(loader);
await assets.load(manifest);
每个条目 type数字 : texture − a 个 Texture· ; binary → Uint8Array· ;
json 编号 : spritesheet ~ 解析的 JSON( 给一个图示表的结果给
parseTexturePackerHash 编号 : parseTexturePackerArray 编号 : parseAseprite) (中文(简体) ).
部分装载失败
load() 一个失败的条目拒绝整个呼叫。 局部时
资产集是可以接受的,使用 loadManifestSettled()数字 :
import { AssetManager, type ManifestEntry } from '@flare-engine/assets';
declare const assets: AssetManager;
declare const manifest: ManifestEntry[];
const { loaded, failed } = await assets.loadManifestSettled(manifest);
if (failed.length) console.warn('some assets failed', failed);
// loaded: string[] of cached keys; failed: { key, error }[]
Sprite 工作表和程序地图集
import { parseTexturePackerHash, createProceduralAtlas, type SkiaAtlasModuleLike } from '@flare-engine/assets';
declare const json: unknown;
declare const skia: SkiaAtlasModuleLike;
const sheet = parseTexturePackerHash(json);
// Procedural placeholder atlas:
const { image, sheet: atlas } = createProceduralAtlas(skia, [
{ name: 'enemy', w: 32, h: 32, color: 0xff_00_ff_00 },
]);
不支持旋转的框架 . TexturePacker的"Allow旋转"包了一些
边框; 剖析器尚不能重新绘制, 因此它们会旋转 。 框架
与 rotated: true 释放出一个可玩可乐 console.warn 命名框架——再导出
无法旋转的地图集。 完全旋转支援是后发射.
见 API 规格。 。 。 .
许可证
阿帕奇 - 2.0