@docyrus/animaguru 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +256 -0
- package/README.md +241 -0
- package/dist/animaguru.js +27338 -0
- package/package.json +37 -0
- package/skills/animaguru/SKILL.md +115 -0
- package/skills/animaguru-advertising/SKILL.md +25 -0
- package/skills/animaguru-advertising/references/brand-bumper.md +11 -0
- package/skills/animaguru-advertising/references/comparison.md +11 -0
- package/skills/animaguru-advertising/references/creator-testimonial.md +11 -0
- package/skills/animaguru-advertising/references/editorial-advertorial.md +11 -0
- package/skills/animaguru-advertising/references/game-reward.md +11 -0
- package/skills/animaguru-advertising/references/offer-promotion.md +11 -0
- package/skills/animaguru-advertising/references/product-launch.md +11 -0
- package/skills/animaguru-advertising/references/product-proof.md +11 -0
- package/skills/animaguru-analog-film-tape/SKILL.md +29 -0
- package/skills/animaguru-analog-film-tape/references/recipe.md +23 -0
- package/skills/animaguru-animated-data-visualization/SKILL.md +39 -0
- package/skills/animaguru-animated-data-visualization/references/data-contract.md +16 -0
- package/skills/animaguru-animated-data-visualization/references/variants.md +17 -0
- package/skills/animaguru-art-deco-motion/SKILL.md +29 -0
- package/skills/animaguru-art-deco-motion/references/recipe.md +22 -0
- package/skills/animaguru-ascii-crt/SKILL.md +29 -0
- package/skills/animaguru-ascii-crt/references/recipe.md +22 -0
- package/skills/animaguru-blueprint-drafting/SKILL.md +29 -0
- package/skills/animaguru-blueprint-drafting/references/recipe.md +22 -0
- package/skills/animaguru-cartoon-character-animation/SKILL.md +35 -0
- package/skills/animaguru-cartoon-character-animation/references/variants.md +17 -0
- package/skills/animaguru-cutout-animation/SKILL.md +33 -0
- package/skills/animaguru-cutout-animation/references/production-recipe.md +37 -0
- package/skills/animaguru-cutout-animation/references/variants.md +17 -0
- package/skills/animaguru-cutout-animation/references/visual-style.md +34 -0
- package/skills/animaguru-dark-tech-stage/SKILL.md +29 -0
- package/skills/animaguru-dark-tech-stage/references/recipe.md +23 -0
- package/skills/animaguru-diagram-formula-motion/SKILL.md +36 -0
- package/skills/animaguru-diagram-formula-motion/references/variants.md +17 -0
- package/skills/animaguru-engraved-relief-print/SKILL.md +29 -0
- package/skills/animaguru-engraved-relief-print/references/recipe.md +24 -0
- package/skills/animaguru-flat-vector-motion/SKILL.md +35 -0
- package/skills/animaguru-flat-vector-motion/references/variants.md +17 -0
- package/skills/animaguru-general-video/SKILL.md +20 -0
- package/skills/animaguru-general-video/references/ambient-loop.md +11 -0
- package/skills/animaguru-general-video/references/music-lyrics.md +11 -0
- package/skills/animaguru-general-video/references/short-film.md +11 -0
- package/skills/animaguru-general-video/references/titles-event.md +11 -0
- package/skills/animaguru-general-video/references/visual-essay.md +11 -0
- package/skills/animaguru-generative-light-signal/SKILL.md +29 -0
- package/skills/animaguru-generative-light-signal/references/recipe.md +23 -0
- package/skills/animaguru-glass-mosaic/SKILL.md +29 -0
- package/skills/animaguru-glass-mosaic/references/recipe.md +23 -0
- package/skills/animaguru-halftone-editorial/SKILL.md +29 -0
- package/skills/animaguru-halftone-editorial/references/recipe.md +23 -0
- package/skills/animaguru-holographic-scan/SKILL.md +29 -0
- package/skills/animaguru-holographic-scan/references/recipe.md +22 -0
- package/skills/animaguru-interface-motion/SKILL.md +36 -0
- package/skills/animaguru-interface-motion/references/screen-mapping.md +16 -0
- package/skills/animaguru-interface-motion/references/variants.md +17 -0
- package/skills/animaguru-isometric-worlds/SKILL.md +35 -0
- package/skills/animaguru-isometric-worlds/references/variants.md +17 -0
- package/skills/animaguru-kinetic-typography/SKILL.md +35 -0
- package/skills/animaguru-kinetic-typography/references/variants.md +17 -0
- package/skills/animaguru-miniature-diorama/SKILL.md +29 -0
- package/skills/animaguru-miniature-diorama/references/recipe.md +23 -0
- package/skills/animaguru-painterly-depth-animation/SKILL.md +35 -0
- package/skills/animaguru-painterly-depth-animation/references/variants.md +17 -0
- package/skills/animaguru-paper-popup/SKILL.md +29 -0
- package/skills/animaguru-paper-popup/references/recipe.md +22 -0
- package/skills/animaguru-photo-footage-editorial/SKILL.md +29 -0
- package/skills/animaguru-photo-footage-editorial/references/recipe.md +23 -0
- package/skills/animaguru-pixel-art-animation/SKILL.md +36 -0
- package/skills/animaguru-pixel-art-animation/references/variants.md +17 -0
- package/skills/animaguru-portal-zoom/SKILL.md +29 -0
- package/skills/animaguru-portal-zoom/references/recipe.md +21 -0
- package/skills/animaguru-risograph-print/SKILL.md +29 -0
- package/skills/animaguru-risograph-print/references/recipe.md +23 -0
- package/skills/animaguru-sand-drawing/SKILL.md +29 -0
- package/skills/animaguru-sand-drawing/references/recipe.md +21 -0
- package/skills/animaguru-shadow-theatre/SKILL.md +29 -0
- package/skills/animaguru-shadow-theatre/references/recipe.md +23 -0
- package/skills/animaguru-silkscreen-poster/SKILL.md +29 -0
- package/skills/animaguru-silkscreen-poster/references/recipe.md +22 -0
- package/skills/animaguru-stop-motion-objects/SKILL.md +29 -0
- package/skills/animaguru-stop-motion-objects/references/recipe.md +23 -0
- package/skills/animaguru-studio-product-reveal/SKILL.md +29 -0
- package/skills/animaguru-studio-product-reveal/references/recipe.md +23 -0
- package/skills/animaguru-video/SKILL.md +79 -0
- package/skills/animaguru-whiteboard-line-drawing/SKILL.md +34 -0
- package/skills/animaguru-whiteboard-line-drawing/references/variants.md +17 -0
- package/templates/video/AGENTS.md +34 -0
- package/templates/video/CLAUDE.md +19 -0
- package/templates/video/README.md +101 -0
- package/templates/video/VIDEO-STYLE-NOTICES.txt +54 -0
- package/templates/video/film.config.json +10 -0
- package/templates/video/gitignore +11 -0
- package/templates/video/index.html +14 -0
- package/templates/video/package.json +28 -0
- package/templates/video/public/brand/logo-mark.svg +5 -0
- package/templates/video/scripts/build.mjs +12 -0
- package/templates/video/scripts/export-html.mjs +12 -0
- package/templates/video/scripts/export-mp4.mjs +209 -0
- package/templates/video/scripts/html-export-plugin.mjs +35 -0
- package/templates/video/scripts/html-export.mjs +54 -0
- package/templates/video/scripts/install-example.mjs +32 -0
- package/templates/video/scripts/review-analysis.mjs +29 -0
- package/templates/video/scripts/review-audio.mjs +24 -0
- package/templates/video/scripts/review.mjs +37 -0
- package/templates/video/scripts/starter-film.sha256 +1 -0
- package/templates/video/shared/locales/en/export.json +10 -0
- package/templates/video/shared/locales/en/film.json +42 -0
- package/templates/video/shared/locales/en/player.json +31 -0
- package/templates/video/shared/locales/en/style-studies.json +168 -0
- package/templates/video/shared/locales/en/timeline.json +33 -0
- package/templates/video/src/assets.ts +4 -0
- package/templates/video/src/download.ts +27 -0
- package/templates/video/src/exporter.ts +70 -0
- package/templates/video/src/film-resources.ts +29 -0
- package/templates/video/src/film.ts +132 -0
- package/templates/video/src/main.ts +219 -0
- package/templates/video/src/resource-timeline.ts +193 -0
- package/templates/video/src/review.ts +50 -0
- package/templates/video/src/studies/film.ts +26 -0
- package/templates/video/src/studies/media.ts +46 -0
- package/templates/video/src/studies/model.ts +60 -0
- package/templates/video/src/studies/pixi-renderer.ts +121 -0
- package/templates/video/src/studies/scenes.ts +410 -0
- package/templates/video/src/studies/timing.ts +53 -0
- package/templates/video/src/studies/variants.ts +39 -0
- package/templates/video/src/style.css +111 -0
- package/templates/video/src/timeline-model.ts +55 -0
- package/templates/video/style-source-provenance.json +11 -0
- package/templates/video/tsconfig.json +15 -0
- package/templates/video/vite.config.mjs +9 -0
- package/vendor/pixijs-skills/LICENSE +21 -0
- package/vendor/pixijs-skills/provenance.json +79 -0
- package/vendor/pixijs-skills/skills/pixijs/SKILL.md +66 -0
- package/vendor/pixijs-skills/skills/pixijs/references/index.md +136 -0
- package/vendor/pixijs-skills/skills/pixijs-accessibility/SKILL.md +224 -0
- package/vendor/pixijs-skills/skills/pixijs-application/SKILL.md +293 -0
- package/vendor/pixijs-skills/skills/pixijs-application/references/application-options.md +314 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/SKILL.md +303 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/background.md +137 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/bundles.md +122 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/caching.md +143 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/compressed-textures.md +120 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/fonts.md +205 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/gif.md +171 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/manifests.md +175 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/progress.md +142 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/resolution.md +142 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/spritesheet.md +119 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/svg.md +132 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/video.md +158 -0
- package/vendor/pixijs-skills/skills/pixijs-blend-modes/SKILL.md +215 -0
- package/vendor/pixijs-skills/skills/pixijs-color/SKILL.md +299 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/SKILL.md +132 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/references/render-loop.md +216 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/references/renderers.md +287 -0
- package/vendor/pixijs-skills/skills/pixijs-create/SKILL.md +276 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/SKILL.md +405 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/references/advanced-gpu.md +244 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/references/uniform-types.md +94 -0
- package/vendor/pixijs-skills/skills/pixijs-environments/SKILL.md +243 -0
- package/vendor/pixijs-skills/skills/pixijs-events/SKILL.md +387 -0
- package/vendor/pixijs-skills/skills/pixijs-filters/SKILL.md +300 -0
- package/vendor/pixijs-skills/skills/pixijs-html-source/SKILL.md +228 -0
- package/vendor/pixijs-skills/skills/pixijs-math/SKILL.md +489 -0
- package/vendor/pixijs-skills/skills/pixijs-migration-v8/SKILL.md +415 -0
- package/vendor/pixijs-skills/skills/pixijs-performance/SKILL.md +489 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-container/SKILL.md +345 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/SKILL.md +243 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/constructor-options.md +155 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/container-hierarchy.md +232 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/layers.md +145 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/masking.md +129 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/render-groups.md +140 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/scene-management.md +169 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/transforms.md +198 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-dom-container/SKILL.md +193 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-gif/SKILL.md +233 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-graphics/SKILL.md +576 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/SKILL.md +141 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-perspective.md +189 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-plane.md +159 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-rope.md +176 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-simple.md +144 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh.md +213 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-particle-container/SKILL.md +323 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/SKILL.md +120 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/animated-sprite.md +262 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/nineslice-sprite.md +202 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/sprite.md +181 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/tiling-sprite.md +216 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/SKILL.md +136 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/bitmap-text.md +232 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/html-text.md +192 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/split-bitmap-text.md +187 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/split-text.md +168 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/text.md +311 -0
- package/vendor/pixijs-skills/skills/pixijs-ticker/SKILL.md +292 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Fonts
|
|
2
|
+
|
|
3
|
+
PixiJS loads two kinds of fonts through `Assets`: web fonts (TTF/OTF/WOFF/WOFF2) via `loadWebFont`, and bitmap fonts (FNT/XML) via `loadBitmapFont`. Use web fonts for `Text` and `HTMLText`; use bitmap fonts for `BitmapText` when you need GPU-friendly rendering without runtime text layout.
|
|
4
|
+
|
|
5
|
+
## Web fonts
|
|
6
|
+
|
|
7
|
+
### Quick Start
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
await Assets.load("fonts/titan-one.woff2");
|
|
11
|
+
|
|
12
|
+
const text = new Text({
|
|
13
|
+
text: "Hello world",
|
|
14
|
+
style: { fontFamily: "Titan One", fontSize: 48 },
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Once the font is loaded, reference it by its derived family name in any `TextStyle`. PixiJS registers the font with the browser's `FontFaceSet`, so DOM elements and Canvas can use it too.
|
|
19
|
+
|
|
20
|
+
### Family name derivation
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// Loaded URL → Derived family name
|
|
24
|
+
// fonts/titan-one.woff → 'Titan One'
|
|
25
|
+
// fonts/open_sans.ttf → 'Open Sans'
|
|
26
|
+
// fonts/my-custom-font.otf → 'My Custom Font'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
By default, the family name is the filename without extension, with dashes and underscores replaced by spaces and title-cased. Override it with `data.family`.
|
|
30
|
+
|
|
31
|
+
### Load options via `data`
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
await Assets.load({
|
|
35
|
+
alias: "hero-font",
|
|
36
|
+
src: "fonts/hero.woff2",
|
|
37
|
+
data: {
|
|
38
|
+
family: "HeroFont",
|
|
39
|
+
weights: ["normal", "bold"],
|
|
40
|
+
style: "italic",
|
|
41
|
+
display: "swap",
|
|
42
|
+
unicodeRange: "U+0000-00FF",
|
|
43
|
+
stretch: "expanded",
|
|
44
|
+
featureSettings: '"liga" 1',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Fields on `data` map directly to FontFace descriptors:
|
|
50
|
+
|
|
51
|
+
| Option | Purpose |
|
|
52
|
+
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
53
|
+
| `family` | Override the derived font family name |
|
|
54
|
+
| `weights` | Array of weights to register. One `FontFace` per weight, all sharing the same URL. Valid values: `'normal'`, `'bold'`, `'100'`–`'900'` |
|
|
55
|
+
| `style` | `'normal'`, `'italic'`, `'oblique'` |
|
|
56
|
+
| `display` | CSS `font-display` (`'auto'`, `'block'`, `'swap'`, `'fallback'`, `'optional'`) |
|
|
57
|
+
| `unicodeRange` | Restrict which codepoints the font covers |
|
|
58
|
+
| `stretch` | `'normal'`, `'condensed'`, `'expanded'`, etc. |
|
|
59
|
+
| `variant` | CSS font-variant value |
|
|
60
|
+
| `featureSettings` | OpenType feature settings like `'"liga" 1, "dlig" 1'` |
|
|
61
|
+
|
|
62
|
+
### Loading multiple weights
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
await Assets.load({
|
|
66
|
+
src: "fonts/inter.woff2",
|
|
67
|
+
data: {
|
|
68
|
+
family: "Inter",
|
|
69
|
+
weights: ["400", "700"],
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
A single URL registers as multiple weights. Use when your font file contains a variable font or when your platform lets one file satisfy multiple weights.
|
|
75
|
+
|
|
76
|
+
### Supported extensions
|
|
77
|
+
|
|
78
|
+
`.ttf`, `.otf`, `.woff`, `.woff2`. WOFF2 is the smallest and universally supported in current browsers. Prefer it unless you're targeting very old environments.
|
|
79
|
+
|
|
80
|
+
## Bitmap fonts
|
|
81
|
+
|
|
82
|
+
### Quick Start
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import "pixi.js/text-bitmap";
|
|
86
|
+
|
|
87
|
+
await Assets.load("fonts/arial.fnt");
|
|
88
|
+
|
|
89
|
+
const text = new BitmapText({
|
|
90
|
+
text: "Score: 9999",
|
|
91
|
+
style: { fontFamily: "Arial", fontSize: 32 },
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The side-effect import registers the `CanvasBitmapTextPipe` and `BitmapTextPipe` rendering pipes. `Assets.load('font.fnt')` works without it and returns a `BitmapFont`, but rendering a `BitmapText` fails at render time without the import.
|
|
96
|
+
|
|
97
|
+
### Supported formats
|
|
98
|
+
|
|
99
|
+
| Extension | Format |
|
|
100
|
+
| --------- | ------------------ |
|
|
101
|
+
| `.fnt` | BMFont text or XML |
|
|
102
|
+
| `.xml` | BMFont XML |
|
|
103
|
+
|
|
104
|
+
The parser sniffs the content to pick between text and XML automatically.
|
|
105
|
+
|
|
106
|
+
### Texture page loading
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
// my-font.fnt references my-font_0.png, my-font_1.png
|
|
110
|
+
await Assets.load("fonts/my-font.fnt");
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Bitmap fonts reference page images by filename in the `.fnt` data. The parser resolves these relative to the `.fnt` URL and loads them automatically. Any search params on the `.fnt` URL (e.g. cache busting) propagate to the page texture URLs.
|
|
114
|
+
|
|
115
|
+
### Signed Distance Field (SDF) fonts
|
|
116
|
+
|
|
117
|
+
The parser detects distance field metadata in the `.fnt` file and enables `linear` scale mode plus disables mipmaps automatically. No extra configuration needed from the caller. SDF fonts stay crisp at any size, so you can render a single bitmap font at many different sizes.
|
|
118
|
+
|
|
119
|
+
### Accessing the BitmapFont instance
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
await Assets.load({ alias: "arial", src: "fonts/arial.fnt" });
|
|
123
|
+
|
|
124
|
+
const font = Assets.get("arial");
|
|
125
|
+
console.log(font.chars);
|
|
126
|
+
console.log(font.fontFamily);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The cached asset is a `BitmapFont` instance. `Assets.get('arial')` and `Assets.get('arial-bitmap')` both return it, and `Assets.get('Arial-bitmap')` works if `fontFamily` matches.
|
|
130
|
+
|
|
131
|
+
## Forcing the font parser
|
|
132
|
+
|
|
133
|
+
If your font URL lacks an extension, force the loader:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
await Assets.load({
|
|
137
|
+
src: "https://cdn.example.com/fonts/abc123",
|
|
138
|
+
parser: "web-font",
|
|
139
|
+
data: { family: "Hero", weights: ["400", "700"] },
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
await Assets.load({
|
|
143
|
+
src: "https://cdn.example.com/fonts/hero-bmfont",
|
|
144
|
+
parser: "bitmap-font",
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
See the main `SKILL.md` section on "Forcing a parser with `parser`" for the full list of parser IDs.
|
|
149
|
+
|
|
150
|
+
## Common Mistakes
|
|
151
|
+
|
|
152
|
+
### [HIGH] Forgetting the bitmap-font import
|
|
153
|
+
|
|
154
|
+
Wrong:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { Assets, BitmapText } from "pixi.js";
|
|
158
|
+
await Assets.load("arial.fnt");
|
|
159
|
+
const text = new BitmapText({ text: "Hi", style: { fontFamily: "Arial" } });
|
|
160
|
+
app.stage.addChild(text);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Correct:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import "pixi.js/text-bitmap";
|
|
167
|
+
import { Assets, BitmapText } from "pixi.js";
|
|
168
|
+
await Assets.load("arial.fnt");
|
|
169
|
+
const text = new BitmapText({ text: "Hi", style: { fontFamily: "Arial" } });
|
|
170
|
+
app.stage.addChild(text);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`Assets.load('arial.fnt')` succeeds in the default bundle and returns a `BitmapFont`, but `'pixi.js/text-bitmap'` registers the `CanvasBitmapTextPipe` and `BitmapTextPipe`. Without it, `BitmapText` renders nothing or errors at render time.
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
### [HIGH] Using Text before the font is loaded
|
|
177
|
+
|
|
178
|
+
Wrong:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const text = new Text({ text: "Hi", style: { fontFamily: "Hero" } });
|
|
182
|
+
Assets.load("fonts/hero.woff2");
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Correct:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
await Assets.load("fonts/hero.woff2");
|
|
189
|
+
const text = new Text({ text: "Hi", style: { fontFamily: "Hero" } });
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The browser falls back to a system font if the named family isn't registered yet, then the `Text` is cached at that fallback style. Reloading the font doesn't repaint existing Text objects.
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
### [MEDIUM] Family name mismatch
|
|
196
|
+
|
|
197
|
+
If you don't pass `data.family`, the family name is derived from the filename. `my_hero_font.woff` becomes `'My Hero Font'`; use exactly that string in your `TextStyle.fontFamily`, or set `data.family` to an explicit value.
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
## API Reference
|
|
201
|
+
|
|
202
|
+
- [loadWebFont](https://pixijs.download/release/docs/assets.loadWebFont.html.md)
|
|
203
|
+
- [loadBitmapFont](https://pixijs.download/release/docs/assets.loadBitmapFont.html.md)
|
|
204
|
+
- [LoadFontData](https://pixijs.download/release/docs/assets.LoadFontData.html.md)
|
|
205
|
+
- [BitmapFont](https://pixijs.download/release/docs/scene.BitmapFont.html.md)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Animated GIFs
|
|
2
|
+
|
|
3
|
+
PixiJS loads animated GIFs through `Assets.load()` and returns a `GifSource` containing all decoded frames. Pass the source to `GifSprite` for playback, looping, and frame control. GIF support is opt-in via the `'pixi.js/gif'` side-effect import.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import "pixi.js/gif";
|
|
9
|
+
import { Assets, GifSprite } from "pixi.js";
|
|
10
|
+
|
|
11
|
+
const source = await Assets.load("explosion.gif");
|
|
12
|
+
const gif = new GifSprite(source);
|
|
13
|
+
app.stage.addChild(gif);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Without `'pixi.js/gif'`, the `.gif` loader parser isn't registered and `Assets.load()` won't know what to do with the file.
|
|
17
|
+
|
|
18
|
+
## Core Patterns
|
|
19
|
+
|
|
20
|
+
### Load options via `data`
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
const source = await Assets.load({
|
|
24
|
+
src: "pixel-art.gif",
|
|
25
|
+
data: {
|
|
26
|
+
fps: 12,
|
|
27
|
+
scaleMode: "nearest",
|
|
28
|
+
resolution: 2,
|
|
29
|
+
autoGenerateMipmaps: false,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`data` accepts `GifBufferOptions`, which extends `CanvasSourceOptions`:
|
|
35
|
+
|
|
36
|
+
| Option | Default | Purpose |
|
|
37
|
+
| --------------------- | ---------- | ---------------------------------------------------------------- |
|
|
38
|
+
| `fps` | `30` | Fallback frame rate when the GIF has no per-frame delay metadata |
|
|
39
|
+
| `scaleMode` | `'linear'` | `'nearest'` for pixel art, `'linear'` for smooth scaling |
|
|
40
|
+
| `resolution` | `1` | Render resolution of the decoded frames |
|
|
41
|
+
| `autoGenerateMipmaps` | `false` | Generate mipmaps for downscaling |
|
|
42
|
+
|
|
43
|
+
Any other `CanvasSourceOptions` field works here too.
|
|
44
|
+
|
|
45
|
+
### GifSprite options
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const gif = new GifSprite({
|
|
49
|
+
source,
|
|
50
|
+
autoPlay: true,
|
|
51
|
+
loop: true,
|
|
52
|
+
animationSpeed: 0.5,
|
|
53
|
+
autoUpdate: true,
|
|
54
|
+
fps: 30,
|
|
55
|
+
onComplete: () => console.log("done"),
|
|
56
|
+
onLoop: () => console.log("looped"),
|
|
57
|
+
onFrameChange: (frame) => console.log(frame),
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Construction options control playback behavior; they're independent of the load-time `data` options.
|
|
62
|
+
|
|
63
|
+
### Loading from a data URI
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const source = await Assets.load(
|
|
67
|
+
"data:image/gif;base64,R0lGODlhAQABAAAAACw...",
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The parser matches both `.gif` file extensions and `data:image/gif` URIs. No extra configuration needed.
|
|
72
|
+
|
|
73
|
+
### Playback control
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
gif.play();
|
|
77
|
+
gif.stop();
|
|
78
|
+
gif.currentFrame = 5;
|
|
79
|
+
gif.animationSpeed = 0.5;
|
|
80
|
+
gif.loop = false;
|
|
81
|
+
|
|
82
|
+
console.log(gif.totalFrames);
|
|
83
|
+
console.log(gif.playing);
|
|
84
|
+
console.log(gif.progress);
|
|
85
|
+
console.log(gif.duration);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Sharing a source across sprites
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const source = await Assets.load("spin.gif");
|
|
92
|
+
|
|
93
|
+
const a = new GifSprite(source);
|
|
94
|
+
const b = new GifSprite(source);
|
|
95
|
+
|
|
96
|
+
a.animationSpeed = 1;
|
|
97
|
+
b.animationSpeed = 0.25;
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Multiple `GifSprite` instances can share the same `GifSource`; each gets independent playback state. The underlying textures are shared, so this is cheap.
|
|
101
|
+
|
|
102
|
+
### Cleanup
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
gif.destroy(); // destroys the sprite, not the source
|
|
106
|
+
gif.destroy(true); // destroys the sprite AND the source (breaks other sprites using it)
|
|
107
|
+
await Assets.unload("explosion.gif"); // unload through the Assets system
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Prefer `Assets.unload` unless you know no other sprite shares the same `GifSource`.
|
|
111
|
+
|
|
112
|
+
## Forcing the GIF parser
|
|
113
|
+
|
|
114
|
+
If your GIF URL lacks an extension, force the parser:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const source = await Assets.load({
|
|
118
|
+
src: "https://cdn.example.com/gif/abc123",
|
|
119
|
+
parser: "gif",
|
|
120
|
+
data: { fps: 24 },
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
See the main `SKILL.md` section on "Forcing a parser with `parser`" for the full list of parser IDs.
|
|
125
|
+
|
|
126
|
+
## Common Mistakes
|
|
127
|
+
|
|
128
|
+
### [CRITICAL] Missing the GIF import
|
|
129
|
+
|
|
130
|
+
Wrong:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import { Assets } from "pixi.js";
|
|
134
|
+
await Assets.load("explosion.gif");
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Correct:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import "pixi.js/gif";
|
|
141
|
+
import { Assets } from "pixi.js";
|
|
142
|
+
await Assets.load("explosion.gif");
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Without `'pixi.js/gif'`, the loader parser isn't registered. The call fails or returns undefined.
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### [MEDIUM] Using GIF when a spritesheet would be cheaper
|
|
149
|
+
|
|
150
|
+
GIF decoding creates one texture per frame. For a 30-frame animation that's 30 separate uploads. A spritesheet packs all frames into a single atlas texture, which batches better and uses less GPU memory. Prefer spritesheets for performance-critical game animations; use GIFs for convenience and one-off effects.
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
### [MEDIUM] destroy(true) when other sprites share the source
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
const source = await Assets.load("spin.gif");
|
|
157
|
+
const a = new GifSprite(source);
|
|
158
|
+
const b = new GifSprite(source);
|
|
159
|
+
|
|
160
|
+
a.destroy(true); // WRONG: also destroys source, breaking sprite b
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Pass `true` to `destroy` only if you know nothing else references the `GifSource`. Otherwise call plain `destroy()` and `Assets.unload()` when the source is no longer needed.
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
## API Reference
|
|
167
|
+
|
|
168
|
+
- [GifSource](https://pixijs.download/release/docs/gif.GifSource.html.md)
|
|
169
|
+
- [GifSprite](https://pixijs.download/release/docs/gif.GifSprite.html.md)
|
|
170
|
+
- [GifBufferOptions](https://pixijs.download/release/docs/gif.GifBufferOptions.html.md)
|
|
171
|
+
- [GifAsset](https://pixijs.download/release/docs/gif.GifAsset.html.md)
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Manifests
|
|
2
|
+
|
|
3
|
+
A manifest is a JSON-shaped description of every bundle in your application. Pass it to `Assets.init({ manifest })` and the resolver registers every bundle at startup, so later code can reference them by name. Use manifests when you know your asset graph upfront and want one source of truth.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
await Assets.init({
|
|
9
|
+
manifest: {
|
|
10
|
+
bundles: [
|
|
11
|
+
{
|
|
12
|
+
name: "load-screen",
|
|
13
|
+
assets: [{ alias: "logo", src: "logo.png" }],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "game",
|
|
17
|
+
assets: [
|
|
18
|
+
{ alias: "hero", src: "hero.{webp,png}" },
|
|
19
|
+
{ alias: "enemies", src: "enemies.json" },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await Assets.loadBundle("load-screen");
|
|
27
|
+
await Assets.loadBundle("game");
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Each bundle has a `name` and an `assets` array of `UnresolvedAsset` entries. Format expansions (`{webp,png}`) and resolution patterns (`@{1,2}x`) work inside `src`.
|
|
31
|
+
|
|
32
|
+
## Core Patterns
|
|
33
|
+
|
|
34
|
+
### Inline manifest object
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const manifest = {
|
|
38
|
+
bundles: [
|
|
39
|
+
{
|
|
40
|
+
name: "ui",
|
|
41
|
+
assets: [
|
|
42
|
+
{ alias: "button", src: "ui/button.png" },
|
|
43
|
+
{ alias: "panel", src: "ui/panel.png" },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
await Assets.init({ manifest });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The manifest can be any plain object matching the `AssetsManifest` shape. Pass it directly to `init`.
|
|
53
|
+
|
|
54
|
+
### Manifest from a URL
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
await Assets.init({ manifest: "assets/manifest.json" });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
When `manifest` is a string, PixiJS loads it as JSON first, then registers the bundles. Useful when your build tooling generates a manifest at deploy time (e.g., with `@assetpack/core`).
|
|
61
|
+
|
|
62
|
+
### Format and resolution patterns in manifests
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const manifest = {
|
|
66
|
+
bundles: [
|
|
67
|
+
{
|
|
68
|
+
name: "hero",
|
|
69
|
+
assets: [{ alias: "hero", src: "hero@{0.5,1,2}x.{webp,avif,png}" }],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The resolver expands the pattern to six candidates and picks the best match based on `window.devicePixelRatio` and browser format support. Configure preferences in `Assets.init({ texturePreference: {...} })`.
|
|
76
|
+
|
|
77
|
+
### Multiple aliases per entry
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const manifest = {
|
|
81
|
+
bundles: [
|
|
82
|
+
{
|
|
83
|
+
name: "characters",
|
|
84
|
+
assets: [
|
|
85
|
+
{ alias: ["hero", "player"], src: "hero.png" },
|
|
86
|
+
{ alias: "npc1", src: "villager.png" },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
An asset can expose multiple aliases. `Assets.load('hero')` and `Assets.load('player')` return the same texture.
|
|
94
|
+
|
|
95
|
+
### Data options in manifest entries
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const manifest = {
|
|
99
|
+
bundles: [
|
|
100
|
+
{
|
|
101
|
+
name: "pixel-art",
|
|
102
|
+
assets: [
|
|
103
|
+
{
|
|
104
|
+
alias: "tile",
|
|
105
|
+
src: "tile.png",
|
|
106
|
+
data: { scaleMode: "nearest" },
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Each asset entry can include a `data` field forwarded to the loader. Use it for `scaleMode`, `autoGenerateMipmaps`, `parseAsGraphicsContext`, FontFace descriptors, etc.
|
|
115
|
+
|
|
116
|
+
### Background-loading from a manifest
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
await Assets.init({ manifest });
|
|
120
|
+
await Assets.loadBundle("load-screen");
|
|
121
|
+
|
|
122
|
+
Assets.backgroundLoadBundle("game");
|
|
123
|
+
await Assets.loadBundle("game");
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
After init, you can start background loading of other bundles immediately. The call is non-blocking; the `await Assets.loadBundle('game')` later resolves quickly if the background work finished.
|
|
127
|
+
|
|
128
|
+
## Common Mistakes
|
|
129
|
+
|
|
130
|
+
### [HIGH] Calling `Assets.init` twice
|
|
131
|
+
|
|
132
|
+
Wrong:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
await Assets.init({ manifest });
|
|
136
|
+
await Assets.init({ basePath: "https://cdn.example.com/" });
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Correct:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
await Assets.init({ manifest, basePath: "https://cdn.example.com/" });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`Assets.init()` can only be called once. The second call is ignored with a warning. Combine all configuration into a single call.
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### [MEDIUM] Missing format expansion on manifest entries
|
|
149
|
+
|
|
150
|
+
Wrong:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
{ alias: 'hero', src: 'hero.webp' }
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Correct:
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
{ alias: 'hero', src: 'hero.{webp,png}' }
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Listing only one format blocks the resolver from falling back on browsers without WebP/AVIF support. Always list at least one fallback.
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### [MEDIUM] Loading manifest after `Assets.add`
|
|
166
|
+
|
|
167
|
+
If you call `Assets.add(...)` or `Assets.addBundle(...)` before `Assets.init({ manifest })`, the manifest bundles will append to the existing state but preference-detection (format, resolution) hasn't run yet. Prefer calling `init` first, then adding ad-hoc assets.
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
## API Reference
|
|
171
|
+
|
|
172
|
+
- [AssetsManifest](https://pixijs.download/release/docs/assets.AssetsManifest.html.md)
|
|
173
|
+
- [Assets](https://pixijs.download/release/docs/assets.Assets.html.md)
|
|
174
|
+
- [Resolver](https://pixijs.download/release/docs/assets.Resolver.html.md)
|
|
175
|
+
- [UnresolvedAsset](https://pixijs.download/release/docs/assets.UnresolvedAsset.html.md)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Progress Tracking
|
|
2
|
+
|
|
3
|
+
`Assets.load` and `Assets.loadBundle` accept a progress callback that fires as each asset completes. Use it to drive loading bars, percentage readouts, or spinner state updates during long loads. The progress value is normalized `[0, 1]` across the entire call.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const loadingBar = new Graphics();
|
|
9
|
+
app.stage.addChild(loadingBar);
|
|
10
|
+
|
|
11
|
+
await Assets.load(["hero.png", "enemy.png", "map.json"], (progress) => {
|
|
12
|
+
loadingBar.clear();
|
|
13
|
+
loadingBar.rect(0, 0, progress * 400, 20).fill(0x66ccff);
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The callback is invoked after each asset resolves. Final invocation reaches `1.0` just before the promise resolves.
|
|
18
|
+
|
|
19
|
+
## Core Patterns
|
|
20
|
+
|
|
21
|
+
### Progress on a single asset
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
await Assets.load("large-atlas.json", (progress) => {
|
|
25
|
+
console.log(`${Math.round(progress * 100)}%`);
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Even for a single asset, the callback fires (typically once, reaching `1.0`). For most cases, progress for a single call is not useful; prefer progress on bundles or arrays.
|
|
30
|
+
|
|
31
|
+
### Progress on an array
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const assets = await Assets.load(
|
|
35
|
+
["hero.png", "enemy.png", "map.json", "music.mp3"],
|
|
36
|
+
(progress) => updateBar(progress),
|
|
37
|
+
);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Progress is distributed evenly across the N assets. When the third asset in a four-asset array finishes, progress is `0.75`.
|
|
41
|
+
|
|
42
|
+
### Progress on a bundle
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
await Assets.loadBundle("level1", (progress) => {
|
|
46
|
+
loadingText.text = `Loading… ${Math.round(progress * 100)}%`;
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Each asset in the bundle contributes equally. If the bundle has 10 entries, each contributes `0.1` to the total.
|
|
51
|
+
|
|
52
|
+
### Progress via `LoadOptions.onProgress`
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
await Assets.load("game.json", {
|
|
56
|
+
onProgress: (progress) => updateBar(progress),
|
|
57
|
+
onError: (err, asset) => {
|
|
58
|
+
const src = typeof asset === "string" ? asset : asset.src;
|
|
59
|
+
console.warn("failed:", src, err);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Instead of a callback as the second argument, pass a `LoadOptions` object. This is the preferred form when you also need error handling or retry strategies. Note that `onError` receives `string | ResolvedAsset`; guard before accessing `.src`.
|
|
65
|
+
|
|
66
|
+
### Global progress across multiple loads
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
async function loadAllWithTotal(tasks: Array<() => Promise<any>>) {
|
|
70
|
+
let done = 0;
|
|
71
|
+
for (const task of tasks) {
|
|
72
|
+
await task();
|
|
73
|
+
done++;
|
|
74
|
+
updateBar(done / tasks.length);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
await loadAllWithTotal([
|
|
79
|
+
() => Assets.load("menu.json"),
|
|
80
|
+
() => Assets.loadBundle("level1"),
|
|
81
|
+
() => Assets.loadBundle("sounds"),
|
|
82
|
+
]);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Progress callbacks are scoped per call. If you need a single bar across several sequential loads, wrap the calls manually and count completions yourself.
|
|
86
|
+
|
|
87
|
+
## Common Mistakes
|
|
88
|
+
|
|
89
|
+
### [HIGH] Treating progress callback as completion
|
|
90
|
+
|
|
91
|
+
Wrong:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
Assets.load("hero.png", (progress) => {
|
|
95
|
+
if (progress === 1) {
|
|
96
|
+
showHero();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Correct:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
await Assets.load("hero.png", (progress) => updateBar(progress));
|
|
105
|
+
showHero();
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`progress === 1` may fire slightly before the returned promise resolves. Always use the `await` or `.then()` to know when loading is truly complete. The progress callback is for UI updates only.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
### [MEDIUM] Progress not updating smoothly
|
|
112
|
+
|
|
113
|
+
Each asset contributes a discrete step. If your bundle has three assets, progress jumps `0 -> 0.33 -> 0.66 -> 1.0`. For a smoother bar, split large bundles into smaller ones, or animate the bar width toward the target value:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
let target = 0;
|
|
117
|
+
await Assets.loadBundle("game", (p) => {
|
|
118
|
+
target = p;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
app.ticker.add(() => {
|
|
122
|
+
loadingBar.width += (target * maxWidth - loadingBar.width) * 0.1;
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
### [MEDIUM] Progress via background loading
|
|
128
|
+
|
|
129
|
+
Wrong:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
Assets.backgroundLoadBundle("game", (p) => updateBar(p));
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Background loading has no progress callback. For visible progress, use `Assets.loadBundle` (foreground). See `references/background.md`.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## API Reference
|
|
139
|
+
|
|
140
|
+
- [Assets](https://pixijs.download/release/docs/assets.Assets.html.md)
|
|
141
|
+
- [LoadOptions](https://pixijs.download/release/docs/assets.LoadOptions.html.md)
|
|
142
|
+
- [ProgressCallback](https://pixijs.download/release/docs/assets.ProgressCallback.html.md)
|