pixijs-assets

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
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.
Assets
API是PixiJS集资源加载器、解析器和缓存于一体的单例对象。可使用它加载纹理、视频、精灵表、字体、JSON及其他资源,支持格式检测、分辨率切换、资源包分组、进度跟踪和GPU资源清理。

Quick Start

快速开始

ts
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()
.
ts
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()
是可选操作,但建议用于设置
basePath
texturePreference
或资源清单。初始化后,可传入URL、别名、数组或
UnresolvedAsset
调用
Assets.load()
;已解析的资源会被缓存,可通过
Assets.get()
重新获取。

Supported file types

支持的文件类型

TypeExtensionsParser IDLoader
Textures
.png
,
.jpg
,
.jpeg
,
.webp
,
.avif
texture
loadTextures
SVG
.svg
svg
loadSvg
(see
references/svg.md
)
Video textures
.mp4
,
.m4v
,
.webm
,
.ogg
,
.ogv
,
.h264
,
.avi
,
.mov
video
loadVideoTextures
(see
references/video.md
)
Sprite sheets
.json
(Spritesheet format)
spritesheet
spritesheetAsset
(see
references/spritesheet.md
)
Bitmap fonts
.fnt
,
.xml
bitmap-font
loadBitmapFont
(loading works by default; rendering
BitmapText
requires
'pixi.js/text-bitmap'
; see
references/fonts.md
)
Web fonts
.ttf
,
.otf
,
.woff
,
.woff2
web-font
loadWebFont
(see
references/fonts.md
)
JSON
.json
json
loadJson
Text
.txt
text
loadTxt
Compressed textures
.basis
,
.dds
,
.ktx
,
.ktx2
basis
,
dds
,
ktx
,
ktx2
See
references/compressed-textures.md
Animated GIFs
.gif
gif
Requires
'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.
类型扩展名解析器ID加载器
纹理
.png
,
.jpg
,
.jpeg
,
.webp
,
.avif
texture
loadTextures
SVG
.svg
svg
loadSvg
(详见
references/svg.md
视频纹理
.mp4
,
.m4v
,
.webm
,
.ogg
,
.ogv
,
.h264
,
.avi
,
.mov
video
loadVideoTextures
(详见
references/video.md
精灵表
.json
(精灵表格式)
spritesheet
spritesheetAsset
(详见
references/spritesheet.md
位图字体
.fnt
,
.xml
bitmap-font
loadBitmapFont
(加载默认生效;渲染
BitmapText
需引入
'pixi.js/text-bitmap'
;详见
references/fonts.md
网页字体
.ttf
,
.otf
,
.woff
,
.woff2
web-font
loadWebFont
(详见
references/fonts.md
JSON
.json
json
loadJson
文本
.txt
text
loadTxt
压缩纹理
.basis
,
.dds
,
.ktx
,
.ktx2
basis
,
dds
,
ktx
,
ktx2
详见
references/compressed-textures.md
GIF动图
.gif
gif
需引入
'pixi.js/gif'
;返回
GifSource
(详见
references/gif.md
解析器ID列的值是你在资源描述符的顶级
parser
字段中传入的内容,用于强制指定加载器。请查看下方“强制指定解析器”部分。

Forcing a parser with
parser

使用
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:
ts
// 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)
默认情况下,PixiJS会通过匹配文件扩展名或MIME类型选择加载器。当你的URL没有扩展名时(如CDN签名URL、Blob URL、API端点、带内容哈希的路径),解析器无法确定使用哪个加载器。此时可在资源描述符的顶级
parser
字段中设置值,强制指定特定加载器:
ts
// 无扩展名的CDN签名URL
const texture = await Assets.load({
  src: "https://cdn.example.com/signed/abc123?token=xyz",
  parser: "texture",
});

// 返回JSON的API端点
const data = await Assets.load({
  alias: "config",
  src: "https://api.example.com/v1/config",
  parser: "json",
});

// 无扩展名且指定字体族的字体URL
await Assets.load({
  src: "https://cdn.example.com/fonts/hero-v2",
  parser: "web-font",
  data: { family: "Hero", weights: ["400", "700"] },
});

// 无文件扩展名的视频流
const clipTexture = await Assets.load({
  src: "https://cdn.example.com/stream/xyz",
  parser: "video",
  data: { mime: "video/mp4", muted: true, playsinline: true },
});
parser
字段位于资源描述符的顶级(与
src
data
同级),而非
data
内部。它可接受上述“支持的文件类型”表格中的任意解析器ID:
  • 'texture'
    ,
    'svg'
    ,
    'video'
    :图片、SVG和视频纹理
  • 'json'
    ,
    'text'
    :JSON和纯文本
  • 'web-font'
    ,
    'bitmap-font'
    :网页字体和位图字体
  • 'spritesheet'
    :纹理图集JSON
  • 'gif'
    :GIF动图(需引入
    'pixi.js/gif'
  • 'basis'
    ,
    'dds'
    ,
    'ktx'
    ,
    'ktx2'
    :压缩纹理(每种都需引入对应的副作用模块)

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.
  • CDN签名URL
    https://cdn.example.com/get?id=abc123
    没有加载器可识别的扩展名。
  • Blob或ObjectURL
    URL.createObjectURL(blob)
    生成的
    blob:...
    URL无扩展名。
  • 自定义路由
    /api/assets/hero-v2
    由服务器决定内容类型。
  • 无后缀的内容哈希路径:部分构建工具生成的文件名类似
    /static/abc123def
    ,而非
    /static/abc123def.png
如果URL扩展名,则无需设置
parser
;让自动检测机制处理即可。仅当检测无法生效时才设置
parser

loadParser
is deprecated

loadParser
已废弃

The v7
loadParser
field still works but emits a deprecation warning. Use
parser
for new code.
ts
// Old (deprecated)
await Assets.load({ src: "...", loadParser: "loadTextures" });

// New
await Assets.load({ src: "...", parser: "texture" });
v7版本的
loadParser
字段仍可使用,但会触发废弃警告。新代码请使用
parser
ts
// 旧写法(已废弃)
await Assets.load({ src: "...", loadParser: "loadTextures" });

// 新写法
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.md
addBundle
,
loadBundle
,
unloadBundle
Declaring everything upfrontreferences/manifests.md
Assets.init({ manifest })
workflows
Cache lookups and cleanupreferences/caching.md
Assets.get
,
Assets.unload
,
Cache
Priming future assetsreferences/background.md
backgroundLoad
,
backgroundLoadBundle
Loading screensreferences/progress.md
onProgress
, LoadOptions progress
GPU-compressed formatsreferences/compressed-textures.md
.ktx2
,
.basis
,
.dds
,
.ktx
Vector vs raster SVGreferences/svg.md
parseAsGraphicsContext
, texture mode
Retina + format detectionreferences/resolution.md
@{1,2}x
,
format
preferences
每个资源工作流都在参考文档中有详细说明。请根据需求选择对应的文档:
主题参考文档适用场景
纹理图集与动画references/spritesheet.md使用
AnimatedSprite
加载精灵表
视频纹理references/video.md
.mp4
,
.webm
、自动播放、循环、移动端适配
网页字体与位图字体references/fonts.md
.woff2
,
.fnt
、字体族、SDF字体
GIF动图references/gif.md
.gif
,
GifSprite
、播放控制
按功能分组资源references/bundles.md
addBundle
,
loadBundle
,
unloadBundle
预先声明所有资源references/manifests.md
Assets.init({ manifest })
工作流
缓存查询与清理references/caching.md
Assets.get
,
Assets.unload
,
Cache
预加载未来资源references/background.md
backgroundLoad
,
backgroundLoadBundle
加载进度屏references/progress.md
onProgress
, LoadOptions进度回调
GPU压缩格式references/compressed-textures.md
.ktx2
,
.basis
,
.dds
,
.ktx
矢量与光栅SVGreferences/svg.md
parseAsGraphicsContext
、纹理模式
Retina屏+格式检测references/resolution.md
@{1,2}x
format
偏好设置

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
    .
  • 需要加载单张图片? 使用
    Assets.load(url)
    。无需额外配置。
  • 需要按关卡/场景分组加载大量资源? 使用资源包。详见
    references/bundles.md
  • 构建时已明确所有资源?
    Assets.init
    中使用资源清单。详见
    references/manifests.md
  • 需要加载进度条?
    Assets.load
    传入进度回调。详见
    references/progress.md
  • 需要关卡间平滑过渡? 后台加载下一关资源。详见
    references/background.md
  • 内存预算有限? 使用压缩纹理,并在切换场景时调用
    Assets.unload
    。详见
    references/compressed-textures.md
    references/caching.md
  • 需要任意尺寸都清晰的SVG图标? 以Graphics形式加载,而非纹理。详见
    references/svg.md
  • Retina屏+WebP/AVIF格式? 配置
    texturePreference
    并使用格式模板。详见
    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.
加载资源时有两个独立的“选项”概念:
  1. LoadOptions
    Assets.load
    /
    loadBundle
    的第二个参数。控制整个加载过程中的错误恢复、重试、进度和完成回调。
  2. data
    :每个资源描述符的字段。将解析器特定选项(缩放模式、分辨率、字体族、自动播放标记等)传递给对应资源的加载器。

LoadOptions (per call)

LoadOptions(单次调用级)

ts
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()
.
ts
await Assets.load(["hero.png", "enemy.png"], {
  onProgress: (p) => updateBar(p),
  onError: (err, url) => {
    const src = typeof url === "string" ? url : url.src;
    console.warn("加载失败:", src, err);
  },
  strategy: "retry",
  retryCount: 3,
  retryDelay: 250,
});
  • onProgress(progress)
    :加载完成度,范围
    [0, 1]
  • onError(error, url)
    url
    类型为
    string | ResolvedAsset
    。读取
    .src
    前需判断;当
    url
    为字符串时,
    .src
    未定义。
  • strategy: 'throw' | 'skip' | 'retry'
    — 默认值
    'throw'
    'skip'
    会返回所有加载成功的资源;
    'retry'
    会重新尝试加载失败的资源。
  • retryCount
    — 默认值
    3
    ,当
    strategy
    'retry'
    时,每个资源的重试次数。
  • retryDelay
    — 默认值
    250
    毫秒,重试间隔时间。
全局默认配置在
Loader.defaultOptions
上,也可在
Assets.init()
中传入
loadOptions
设置。

data
options (per asset)

data
选项(单资源级)

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 type
data
shape
Key optionsReference
Texture (image)
TextureSourceOptions
resolution
,
scaleMode
,
alphaMode
,
autoGenerateMipmaps
,
antialias
,
addressMode
references/resolution.md
SVG
{ parseAsGraphicsContext?, resolution? }
parseAsGraphicsContext
for Graphics mode;
resolution
for sharper raster
references/svg.md
Video
VideoSourceOptions
autoPlay
,
loop
,
muted
,
playsinline
,
preload
,
updateFPS
,
crossorigin
,
mime
references/video.md
Web font
LoadFontData
family
,
weights
,
style
,
display
,
unicodeRange
,
featureSettings
references/fonts.md
Bitmap font(none; auto-configured)Distance-field detection sets scale mode and mipmaps
references/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 frames
references/spritesheet.md
GIF
GifBufferOptions
fps
,
scaleMode
,
resolution
,
autoGenerateMipmaps
references/gif.md
Compressed texture
TextureSourceOptions
scaleMode
,
addressMode
,
autoGenerateMipmaps
references/compressed-textures.md
JSON / Text(none)Returned as-is
Example combining
LoadOptions
and
data
:
ts
await Assets.load(
  {
    alias: "hero",
    src: "hero.png",
    data: { scaleMode: "nearest", resolution: 2 },
  },
  { strategy: "retry", retryCount: 3 },
);
Inside a manifest or bundle, every entry can carry its own
data
:
ts
await Assets.init({
  manifest: {
    bundles: [
      {
        name: "level1",
        assets: [
          { alias: "tiles", src: "tiles.png", data: { scaleMode: "nearest" } },
          { alias: "font", src: "hero.woff2", data: { family: "Hero" } },
          {
            alias: "clip",
            src: "intro.mp4",
            data: { autoPlay: false, muted: true },
          },
        ],
      },
    ],
  },
});
每个加载器解析器会从资源描述符的
data
字段读取专属选项。请使用下表为每种资源类型选择正确的选项:
资源类型
data
结构
核心选项参考文档
纹理(图片)
TextureSourceOptions
resolution
,
scaleMode
,
alphaMode
,
autoGenerateMipmaps
,
antialias
,
addressMode
references/resolution.md
SVG
{ parseAsGraphicsContext?, resolution? }
parseAsGraphicsContext
启用Graphics模式;
resolution
提升光栅化清晰度
references/svg.md
视频
VideoSourceOptions
autoPlay
,
loop
,
muted
,
playsinline
,
preload
,
updateFPS
,
crossorigin
,
mime
references/video.md
网页字体
LoadFontData
family
,
weights
,
style
,
display
,
unicodeRange
,
featureSettings
references/fonts.md
位图字体无;自动配置距离场检测会设置缩放模式和多级纹理
references/fonts.md
精灵表
{ texture?, imageFilename?, ignoreMultiPack?, textureOptions?, cachePrefix? }
textureOptions
TextureSourceOptions
(如
scaleMode
)传递给图集图片;
texture
跳过图片加载;
imageFilename
覆盖引用的图片;
ignoreMultiPack
跳过多图集后续加载;
cachePrefix
为帧添加命名空间
references/spritesheet.md
GIF
GifBufferOptions
fps
,
scaleMode
,
resolution
,
autoGenerateMipmaps
references/gif.md
压缩纹理
TextureSourceOptions
scaleMode
,
addressMode
,
autoGenerateMipmaps
references/compressed-textures.md
JSON / 文本原样返回
结合
LoadOptions
data
的示例:
ts
await Assets.load(
  {
    alias: "hero",
    src: "hero.png",
    data: { scaleMode: "nearest", resolution: 2 },
  },
  { strategy: "retry", retryCount: 3 },
);
在资源清单或资源包中,每个条目都可携带自己的
data
ts
await Assets.init({
  manifest: {
    bundles: [
      {
        name: "level1",
        assets: [
          { alias: "tiles", src: "tiles.png", data: { scaleMode: "nearest" } },
          { alias: "font", src: "hero.woff2", data: { family: "Hero" } },
          {
            alias: "clip",
            src: "intro.mp4",
            data: { autoPlay: false, muted: true },
          },
        ],
      },
    ],
  },
});

Runtime configuration

运行时配置

Assets.init(options)
accepts, alongside
basePath
and
manifest
:
  • defaultSearchParams
    — string or
    Record<string, any>
    appended to every resolved URL. Useful for cache busting.
  • skipDetections: boolean
    — bypass browser format detection for faster init. Requires explicit
    texturePreference.format
    .
  • bundleIdentifier: BundleIdentifierOptions
    — customize how bundle keys resolve so the same alias can live in multiple bundles.
  • loadOptions: Partial<LoadOptions>
    — set the default
    strategy
    ,
    retryCount
    ,
    retryDelay
    , and callbacks for every subsequent
    Assets.load
    call.
  • preferences: Partial<AssetsPreferences>
    crossOrigin
    ,
    preferWorkers
    ,
    preferCreateImageBitmap
    ,
    parseAsGraphicsContext
    .
After init, preferences can still be tuned:
ts
Assets.setPreferences({
  crossOrigin: "anonymous",
  preferCreateImageBitmap: false,
});

for (const detection of Assets.detections) {
  console.log(detection.extension);
}

Assets.reset();
  • Assets.setPreferences(preferences)
    — push new preferences to every parser that supports them.
  • Assets.detections
    — getter exposing the registered
    FormatDetectionParser
    list; use when inspecting what formats the current environment advertises.
  • Assets.reset()
    — internal full reset (resolver + loader + cache). Intended for tests so a fresh
    Assets.init
    can run.
Assets.init(options)
除了接受
basePath
manifest
外,还支持:
  • defaultSearchParams
    — 字符串或
    Record<string, any>
    ,会追加到每个解析后的URL中。适用于缓存刷新。
  • skipDetections: boolean
    — 跳过浏览器格式检测,加快初始化速度。需显式设置
    texturePreference.format
  • bundleIdentifier: BundleIdentifierOptions
    — 自定义资源包键的解析方式,使同一别名可存在于多个资源包中。
  • loadOptions: Partial<LoadOptions>
    — 为后续所有
    Assets.load
    调用设置默认的
    strategy
    retryCount
    retryDelay
    和回调函数。
  • preferences: Partial<AssetsPreferences>
    crossOrigin
    ,
    preferWorkers
    ,
    preferCreateImageBitmap
    ,
    parseAsGraphicsContext
初始化后,仍可调整偏好设置:
ts
Assets.setPreferences({
  crossOrigin: "anonymous",
  preferCreateImageBitmap: false,
});

for (const detection of Assets.detections) {
  console.log(detection.extension);
}

Assets.reset();
  • Assets.setPreferences(preferences)
    — 将新的偏好设置推送给所有支持的解析器。
  • Assets.detections
    — 获取已注册的
    FormatDetectionParser
    列表;用于检查当前环境支持的格式。
  • Assets.reset()
    — 内部完全重置(解析器+加载器+缓存)。主要用于测试,以便重新执行
    Assets.init

Common Mistakes

常见错误

[CRITICAL] Using
Texture.from(url)
to load

[严重] 使用
Texture.from(url)
加载资源

Wrong:
ts
const texture = Texture.from("https://example.com/image.png");
Correct:
ts
const texture = await Assets.load("https://example.com/image.png");
In v8,
Texture.from()
only reads the cache. It does not fetch from a URL. Use
Assets.load()
first; the return value is the texture itself.
错误写法:
ts
const texture = Texture.from("https://example.com/image.png");
正确写法:
ts
const texture = await Assets.load("https://example.com/image.png");
在v8版本中,
Texture.from()
仅读取缓存,不会从URL获取资源。请先使用
Assets.load()
;其返回值就是纹理本身。

[HIGH] Using positional
Assets.add
signature

[高危] 使用
Assets.add
的位置参数签名

Wrong:
ts
Assets.add("bunny", "bunny.png");
Correct:
ts
Assets.add({ alias: "bunny", src: "bunny.png" });
The positional
Assets.add(key, url)
form was removed in v8. Use the options object with
alias
and
src
properties.
错误写法:
ts
Assets.add("bunny", "bunny.png");
正确写法:
ts
Assets.add({ alias: "bunny", src: "bunny.png" });
Assets.add(key, url)
的位置参数形式在v8中已被移除。请使用包含
alias
src
属性的选项对象。

[HIGH] Not unloading textures between levels

[高危] 关卡切换时未卸载纹理

Assets.load()
caches textures indefinitely. For level-based games or screens with distinct asset sets, call
Assets.unloadBundle()
when transitioning to release GPU memory.
Assets.load()
会无限期缓存纹理。对于关卡类游戏或资源集独立的场景,切换时请调用
Assets.unloadBundle()
释放GPU内存。

API Reference

API参考