首页/游戏开发/pixijs-assets
P

pixijs-assets

by @pixijsv
4.3(120)

此技能专为PixiJS v8设计,提供强大的资源加载、管理和缓存功能。它能高效处理纹理、视频、精灵表、字体等多种游戏资产,支持捆绑、清单、背景加载、进度跟踪及GPU清理,显著简化开发流程,提升游戏性能和用户体验。

pixijsasset-managementgame-developmentresource-loadingweb-game-devGitHub
安装方式
npx skills add https://github.com/pixijs/pixijs-skills --skill pixijs-assets
compare_arrows

Before / After 效果对比

1
使用前

手动管理PixiJS游戏资源,需要编写大量代码处理不同文件类型、缓存、分辨率适配和错误处理,耗时且易出错,导致项目开发周期延长和维护成本增加。

使用后

使用PixiJS Assets API,通过统一接口高效加载、管理和缓存各类游戏资源,自动化处理复杂逻辑,显著提升开发效率和资源管理质量,缩短上市时间。

SKILL.md

The Assets API is PixiJS's asset loader, resolver, and cache in one singleton. Use it to load textures, video, spritesheets, fonts, JSON, and other resources with format detection, resolution switching, bundle grouping, progress tracking, and GPU cleanup.

Quick Start

await Assets.init({ basePath: "/static/" });

const texture = await Assets.load("bunny.png");
const sprite = new Sprite(texture);
app.stage.addChild(sprite);

const [hero, enemy] = await Assets.load(["hero.png", "enemy.png"]);

await Assets.load({
  alias: "logo",
  src: "logo.webp",
});

const logo = new Sprite(Assets.get("logo"));

Assets.init() is optional but recommended for setting basePath, texturePreference, or a manifest. After init, call Assets.load() with a URL, alias, array, or UnresolvedAsset; resolved assets are cached and re-resolved by Assets.get().

Supported file types

TypeExtensionsParser IDLoader
Textures.png, .jpg, .jpeg, .webp, .aviftextureloadTextures
SVG.svgsvgloadSvg (see references/svg.md)
Video textures.mp4, .m4v, .webm, .ogg, .ogv, .h264, .avi, .movvideoloadVideoTextures (see references/video.md)
Sprite sheets.json (Spritesheet format)spritesheetspritesheetAsset (see references/spritesheet.md)
Bitmap fonts.fnt, .xmlbitmap-fontloadBitmapFont (loading works by default; rendering BitmapText requires 'pixi.js/text-bitmap'; see references/fonts.md)
Web fonts.ttf, .otf, .woff, .woff2web-fontloadWebFont (see references/fonts.md)
JSON.jsonjsonloadJson
Text.txttextloadTxt
Compressed textures.basis, .dds, .ktx, .ktx2basis, dds, ktx, ktx2See references/compressed-textures.md
Animated GIFs.gifgifRequires 'pixi.js/gif'; returns GifSource (see references/gif.md)

The Parser ID column is the value you pass to the top-level parser field on an asset descriptor to force a specific loader. See "Forcing a parser" below.

Forcing a parser with parser

By default, PixiJS picks a loader by matching the file extension or MIME type. When your URL lacks an extension (CDN signed URLs, blob URLs, API endpoints, content-hashed paths), the resolver can't tell the loader what to do. Set the top-level parser field on the asset descriptor to force a specific loader:

// Signed CDN URL with no extension
const texture = await Assets.load({
  src: "https://cdn.example.com/signed/abc123?token=xyz",
  parser: "texture",
});

// API endpoint that returns JSON
const data = await Assets.load({
  alias: "config",
  src: "https://api.example.com/v1/config",
  parser: "json",
});

// Extension-less font URL with explicit family
await Assets.load({
  src: "https://cdn.example.com/fonts/hero-v2",
  parser: "web-font",
  data: { family: "Hero", weights: ["400", "700"] },
});

// Video stream without a file extension
const clipTexture = await Assets.load({
  src: "https://cdn.example.com/stream/xyz",
  parser: "video",
  data: { mime: "video/mp4", muted: true, playsinline: true },
});

The parser field goes at the top level of the asset descriptor (alongside src and data), not inside data. It takes any parser ID from the "Supported file types" table above:

  • 'texture', 'svg', 'video': image, SVG, and video textures
  • 'json', 'text': JSON and plain text
  • 'web-font', 'bitmap-font': web and bitmap fonts
  • 'spritesheet': texture atlas JSON
  • 'gif': animated GIFs (requires 'pixi.js/gif')
  • 'basis', 'dds', 'ktx', 'ktx2': compressed textures (each requires its side-effect import)

When you need it

  • Signed CDN URLs: https://cdn.example.com/get?id=abc123 has no extension the loader can test against.
  • Blob or ObjectURL: URL.createObjectURL(blob) produces blob:... URLs with no extension.
  • Custom routing: /api/assets/hero-v2 where the server decides the content type.
  • Content-hashed paths without suffix: some build pipelines produce names like /static/abc123def instead of /static/abc123def.png.

If the URL does have an extension, you don't need parser; let auto-detection do its job. Only set parser when detection can't work.

loadParser is deprecated

The v7 loadParser field still works but emits a deprecation warning. Use parser for new code.

// Old (deprecated)
await Assets.load({ src: "...", loadParser: "loadTextures" });

// New
await Assets.load({ src: "...", parser: "texture" });

Topics

Every asset workflow is covered in a reference file. Pick the one that matches the question:

TopicReferenceWhen
Texture atlases and animationsreferences/spritesheet.mdLoading sprite sheets with AnimatedSprite
Video texturesreferences/video.md.mp4, .webm, autoplay, looping, mobile
Web and bitmap fontsreferences/fonts.md.woff2, .fnt, font families, SDF fonts
Animated GIFsreferences/gif.md.gif, GifSprite, playback control
Grouping assets by featurereferences/bundles.mdaddBundle, loadBundle, unloadBundle
Declaring everything upfrontreferences/manifests.mdAssets.init({ manifest }) workflows
Cache lookups and cleanupreferences/caching.mdAssets.get, Assets.unload, Cache
Priming future assetsreferences/background.mdbackgroundLoad, backgroundLoadBundle
Loading screensreferences/progress.mdonProgress, LoadOptions progress
GPU-compressed formatsreferences/compressed-textures.md.ktx2, .basis, .dds, .ktx
Vector vs raster SVGreferences/svg.mdparseAsGraphicsContext, texture mode
Retina + format detectionreferences/resolution.md@{1,2}x, format preferences

Decision guide

  • Need to load a single image? Use Assets.load(url). No setup required.
  • Loading many assets grouped by level/scene? Use a bundle. See references/bundles.md.
  • Know all assets at build time? Use a manifest in Assets.init. See references/manifests.md.
  • Need a loading bar? Pass a progress callback to Assets.load. See references/progress.md.
  • Smooth transitions between levels? Background-load the next level. See references/background.md.
  • Memory budget matters? Use compressed textures and Assets.unload between screens. See references/compressed-textures.md and references/caching.md.
  • Need crisp SVG icons at any size? Load as Graphics, not texture. See references/svg.md.
  • Retina + WebP/AVIF? Configure texturePreference and use format patterns. See references/resolution.md.

Load options and error handling

There are two separate "options" concepts when loading assets:

  1. LoadOptions: the second argument to Assets.load/loadBundle. Controls error recovery, retries, progress, and completion callbacks across a whole load.
  2. data: a field on each asset descriptor. Forwards parser-specific options (scale mode, resolution, font family, autoplay flags, etc.) to the specific loader for that asset.

LoadOptions (per call)

await Assets.load(["hero.png", "enemy.png"], {
  onProgress: (p) => updateBar(p),
  onError: (err, url) => {
    const src = typeof url === "string" ? url : url.src;
    console.warn("failed:", src, err);
  },
  strategy: "retry",
  retryCount: 3,
  retryDelay: 250,
});
  • onProgress(progress): [0, 1] as assets in the call complete.
  • onError(error, url): url is string | ResolvedAsset. Guard before reading .src; when url is a string, .src is undefined.
  • strategy: 'throw' | 'skip' | 'retry' — default 'throw'. 'skip' resolves with any successful assets; 'retry' reattempts the failed ones.
  • retryCount — default 3, retries per asset when strategy is 'retry'.
  • retryDelay — default 250 ms between retries.

Global defaults live on Loader.defaultOptions, or pass loadOptions to Assets.init().

data options (per asset)

Each loader parser reads its own options from the data field on the asset descriptor. Use the table below to pick the right options for each asset type:

Asset typedata shapeKey optionsReference
Texture (image)TextureSourceOptionsresolution, scaleMode, alphaMode, autoGenerateMipmaps, antialias, addressModereferences/resolution.md
SVG{ parseAsGraphicsContext?, resolution? }parseAsGraphicsContext for Graphics mode; resolution for sharper rasterreferences/svg.md
VideoVideoSourceOptionsautoPlay, loop, muted, playsinline, preload, updateFPS, crossorigin, mimereferences/video.md
Web fontLoadFontDatafamily, weights, style, display, unicodeRange, featureSettingsreferences/fonts.md
Bitmap font(none; auto-configured)Distance-field detection sets scale mode and mipmapsreferences/fonts.md
Spritesheet{ texture?, imageFilename?, ignoreMultiPack?, textureOptions?, cachePrefix? }textureOptions forwards TextureSourceOptions (e.g. scaleMode) to the atlas image; texture to skip image load; imageFilename to override the referenced image; ignoreMultiPack to skip multi-pack follow-ups; cachePrefix to namespace framesreferences/spritesheet.md
GIFGifBufferOptionsfps, scaleMode, resolution, autoGenerateMipmapsreferences/gif.md
Compressed textureTextureSourceOptionsscaleMode, addressMode, autoGenerateMipmaps

...

用户评价 (0)

发表评价

效果
易用性
文档
兼容性

暂无评价

统计数据

安装量2.5K
评分4.3 / 5.0
版本
更新日期2026年7月9日
对比案例1 组

用户评分

4.3(120)
5
37%
4
43%
3
13%
2
5%
1
2%

为此 Skill 评分

0.0

兼容平台

🤖claude-code

时间线

创建2026年5月28日
最后更新2026年7月9日
🎁 Agent 知识卡片
调研问卷