@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,142 @@
|
|
|
1
|
+
# Resolution and Format Detection
|
|
2
|
+
|
|
3
|
+
PixiJS's asset resolver can pick the best asset variant for the current device based on pixel density (`@0.5x`, `@1x`, `@2x`) and supported image formats (`avif`, `webp`, `png`). Use resolution and format patterns to serve one asset spec that adapts to retina displays, format support, and bandwidth budgets.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
await Assets.init({
|
|
9
|
+
texturePreference: {
|
|
10
|
+
resolution: window.devicePixelRatio,
|
|
11
|
+
format: ["avif", "webp", "png"],
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
Assets.add({ alias: "hero", src: "hero@{0.5,1,2}x.{webp,png}" });
|
|
16
|
+
|
|
17
|
+
const texture = await Assets.load("hero");
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The resolver expands the pattern to six candidates (`hero@0.5x.webp`, `hero@0.5x.png`, `hero@1x.webp`, ...) and picks the best match based on device pixel ratio and format support.
|
|
21
|
+
|
|
22
|
+
## Core Patterns
|
|
23
|
+
|
|
24
|
+
### Configuring preferences at init
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
await Assets.init({
|
|
28
|
+
texturePreference: {
|
|
29
|
+
resolution: window.devicePixelRatio, // e.g., 2 on retina
|
|
30
|
+
format: ["avif", "webp", "png"], // preferred-first order
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- `resolution` is a single number (best-match threshold) or array of acceptable resolutions.
|
|
36
|
+
- `format` is ordered by preference. The resolver tries each in turn and uses the first one the browser supports.
|
|
37
|
+
|
|
38
|
+
### Resolution patterns in src
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
Assets.add({ alias: "bg", src: "bg@{0.5,1,2}x.png" });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The resolver expands this to `bg@0.5x.png`, `bg@1x.png`, `bg@2x.png` and picks based on `texturePreference.resolution`. Encoded resolution sets the texture's source resolution automatically, so the sprite's `width` / `height` appear as logical size regardless of the file chosen.
|
|
45
|
+
|
|
46
|
+
### Format patterns in src
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
Assets.add({ alias: "icon", src: "icon.{avif,webp,png}" });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Format detection runs once during `Assets.init()`. The resolver learns which formats the browser supports, then picks the highest-preference supported format per load.
|
|
53
|
+
|
|
54
|
+
### Combined resolution + format
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
Assets.add({ alias: "hero", src: "hero@{0.5,1,2}x.{avif,webp,png}" });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Both patterns can appear in the same `src`. The resolver does a Cartesian product: 3 resolutions × 3 formats = 9 candidates. It picks the best combination based on both preferences.
|
|
61
|
+
|
|
62
|
+
### Manual resolution override
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
Assets.add({
|
|
66
|
+
alias: "sharp",
|
|
67
|
+
src: "sharp.png",
|
|
68
|
+
data: { resolution: 2 },
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
If a file is already at a known resolution but lacks the `@2x` filename suffix, pass `resolution` in `data` to tell the loader. Useful when your tooling doesn't produce suffixed filenames.
|
|
73
|
+
|
|
74
|
+
### Custom retina prefix
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { Resolver } from "pixi.js";
|
|
78
|
+
|
|
79
|
+
Resolver.RETINA_PREFIX = /@([0-9\.]+)density/;
|
|
80
|
+
|
|
81
|
+
Assets.add({ alias: "hero", src: "hero@{1,2}density.png" });
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Change the resolution filename pattern if your build pipeline uses a different convention. Default is `/@([0-9\.]+)x/`.
|
|
85
|
+
|
|
86
|
+
### Skipping format detection
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
await Assets.init({
|
|
90
|
+
skipDetections: true,
|
|
91
|
+
texturePreference: { format: ["webp"] },
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
If you know your target browser supports a specific format, `skipDetections: true` skips the runtime detection (a small init-time saving). Useful for embedded or kiosk deployments where format support is fixed.
|
|
96
|
+
|
|
97
|
+
## Common Mistakes
|
|
98
|
+
|
|
99
|
+
### [HIGH] Wrong pattern syntax
|
|
100
|
+
|
|
101
|
+
Wrong:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
Assets.add({ alias: "hero", src: "hero@[1,2]x.png" });
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Correct:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
Assets.add({ alias: "hero", src: "hero@{1,2}x.png" });
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The expansion syntax uses `{}` (like shell brace expansion), not `[]`. Square brackets aren't recognized and the resolver tries to load the literal filename.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### [MEDIUM] Missing fallback format
|
|
117
|
+
|
|
118
|
+
Wrong:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
Assets.add({ alias: "hero", src: "hero.avif" });
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Correct:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
Assets.add({ alias: "hero", src: "hero.{avif,png}" });
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
If a browser doesn't support AVIF, the loader fails. Always list at least one fallback format that all target browsers support.
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### [MEDIUM] Mismatch between spritesheet.json `meta.scale` and actual image
|
|
134
|
+
|
|
135
|
+
In v8, a spritesheet's `meta.scale` field directly sets the resolution of the atlas texture. If the JSON says `"1"` but the image was exported at 2x, frames render at double the intended size. Verify `meta.scale` matches the actual image resolution; atlas tools like TexturePacker set this automatically.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## API Reference
|
|
139
|
+
|
|
140
|
+
- [Assets](https://pixijs.download/release/docs/assets.Assets.html.md)
|
|
141
|
+
- [Resolver](https://pixijs.download/release/docs/assets.Resolver.html.md)
|
|
142
|
+
- [AssetInitOptions](https://pixijs.download/release/docs/assets.AssetInitOptions.html.md)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Spritesheet: Texture Atlases and Animations
|
|
2
|
+
|
|
3
|
+
Load and use texture atlases and animation sheets with PixiJS's `Spritesheet` class. Atlases reduce draw calls by packing many textures into a single image.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const sheet = await Assets.load("spritesheet.json");
|
|
9
|
+
|
|
10
|
+
const hero = new Sprite(sheet.textures["hero.png"]);
|
|
11
|
+
app.stage.addChild(hero);
|
|
12
|
+
|
|
13
|
+
const walk = new AnimatedSprite(sheet.animations["walk"]);
|
|
14
|
+
walk.animationSpeed = 0.15;
|
|
15
|
+
walk.play();
|
|
16
|
+
app.stage.addChild(walk);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
When loaded through `Assets.load()`, the JSON file is fetched, the atlas image is loaded, and `sheet.parse()` is called automatically. The returned object is a `Spritesheet` instance.
|
|
20
|
+
|
|
21
|
+
## Core Patterns
|
|
22
|
+
|
|
23
|
+
### SpritesheetData JSON format
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"frames": {
|
|
28
|
+
"hero.png": {
|
|
29
|
+
"frame": { "x": 0, "y": 0, "w": 64, "h": 64 },
|
|
30
|
+
"sourceSize": { "w": 64, "h": 64 },
|
|
31
|
+
"spriteSourceSize": { "x": 0, "y": 0, "w": 64, "h": 64 },
|
|
32
|
+
"anchor": { "x": 0.5, "y": 0.5 },
|
|
33
|
+
"borders": { "left": 10, "top": 10, "right": 10, "bottom": 10 }
|
|
34
|
+
},
|
|
35
|
+
"walk_01.png": {
|
|
36
|
+
"frame": { "x": 64, "y": 0, "w": 64, "h": 64 },
|
|
37
|
+
"rotated": true,
|
|
38
|
+
"trimmed": true,
|
|
39
|
+
"sourceSize": { "w": 80, "h": 80 },
|
|
40
|
+
"spriteSourceSize": { "x": 8, "y": 8, "w": 64, "h": 64 }
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"animations": {
|
|
44
|
+
"walk": ["walk_01.png", "walk_02.png", "walk_03.png"]
|
|
45
|
+
},
|
|
46
|
+
"meta": {
|
|
47
|
+
"image": "spritesheet.png",
|
|
48
|
+
"size": { "w": 512, "h": 256 },
|
|
49
|
+
"scale": "1"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Key fields:
|
|
55
|
+
|
|
56
|
+
- `frames` maps frame names to rectangle data, trim info, anchors, and 9-slice borders.
|
|
57
|
+
- `rotated` indicates the frame is stored rotated 90 degrees in the atlas. The parser swaps width/height automatically.
|
|
58
|
+
- `trimmed` indicates transparent padding was removed. `sourceSize` is the original dimensions; `spriteSourceSize` is the trimmed region within it.
|
|
59
|
+
- `animations` maps animation names to ordered arrays of frame names.
|
|
60
|
+
- `meta.scale` sets the resolution of the texture source. `"2"` means the atlas is @2x.
|
|
61
|
+
- `meta.image` is the atlas image filename, resolved relative to the JSON file.
|
|
62
|
+
|
|
63
|
+
### Manual Spritesheet creation
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const texture = await Assets.load("atlas.png");
|
|
67
|
+
const sheet = new Spritesheet({
|
|
68
|
+
texture,
|
|
69
|
+
data: spritesheetJsonData,
|
|
70
|
+
cachePrefix: "myAtlas_",
|
|
71
|
+
});
|
|
72
|
+
await sheet.parse();
|
|
73
|
+
|
|
74
|
+
const frame = new Sprite(sheet.textures["hero.png"]);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`parse()` is async for large spritesheets (over 1000 frames); it batches texture creation across multiple frames. For smaller sheets, `parseSync()` is also available.
|
|
78
|
+
|
|
79
|
+
`cachePrefix` prepends a string to all cached texture names, preventing collisions when multiple atlases share frame names (e.g., `"hero.png"` in two different sheets).
|
|
80
|
+
|
|
81
|
+
### Preloaded texture with Assets
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
const atlasTexture = await Assets.load("images/spritesheet.png");
|
|
85
|
+
|
|
86
|
+
Assets.add({
|
|
87
|
+
alias: "atlas",
|
|
88
|
+
src: "images/spritesheet.json",
|
|
89
|
+
data: { texture: atlasTexture },
|
|
90
|
+
});
|
|
91
|
+
const sheet = await Assets.load("atlas");
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Multi-pack spritesheets
|
|
95
|
+
|
|
96
|
+
When `meta.related_multi_packs` is present, the loader automatically loads and links related spritesheets. All linked sheets are accessible via `sheet.linkedSheets`.
|
|
97
|
+
|
|
98
|
+
### Cleanup
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
sheet.destroy();
|
|
102
|
+
sheet.destroy(true); // also destroys the base atlas texture
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Common Mistakes
|
|
106
|
+
|
|
107
|
+
### [HIGH] Spritesheet meta.scale behavior change
|
|
108
|
+
|
|
109
|
+
In v8, `meta.scale` directly sets the texture source resolution. If your atlas was exported at @2x but `meta.scale` says `"1"`, frames render at double the intended size. Ensure `meta.scale` matches the actual resolution of the atlas image. Tools like TexturePacker set this automatically.
|
|
110
|
+
|
|
111
|
+
### [MEDIUM] Not awaiting spritesheet parse
|
|
112
|
+
|
|
113
|
+
`parse()` is async. Accessing `sheet.textures` before it resolves returns undefined entries. When loading via `Assets.load()`, parsing is handled automatically.
|
|
114
|
+
|
|
115
|
+
## API Reference
|
|
116
|
+
|
|
117
|
+
- [Spritesheet](https://pixijs.download/release/docs/assets.Spritesheet.html.md)
|
|
118
|
+
- [spritesheetAsset](https://pixijs.download/release/docs/assets.spritesheetAsset.html.md)
|
|
119
|
+
- [AnimatedSprite](https://pixijs.download/release/docs/scene.AnimatedSprite.html.md)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# SVG Loading
|
|
2
|
+
|
|
3
|
+
PixiJS loads `.svg` files in one of two modes: rasterized to a texture (fast, fixed resolution) or parsed into a `GraphicsContext` (scalable vector, reusable across `Graphics` instances). Choose texture mode for backgrounds and decorative elements at a fixed size; choose Graphics mode for icons, UI elements, or anything that needs to scale or be modified at runtime.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const svgTexture = await Assets.load("icon.svg");
|
|
9
|
+
const sprite = new Sprite(svgTexture);
|
|
10
|
+
|
|
11
|
+
const svgContext = await Assets.load({
|
|
12
|
+
src: "icon.svg",
|
|
13
|
+
data: { parseAsGraphicsContext: true },
|
|
14
|
+
});
|
|
15
|
+
const graphic = new Graphics(svgContext);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
By default, SVG files rasterize to a texture at their native size. Pass `parseAsGraphicsContext: true` in the `data` field to parse as vector geometry instead.
|
|
19
|
+
|
|
20
|
+
## Core Patterns
|
|
21
|
+
|
|
22
|
+
### Texture mode (default)
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const icon = await Assets.load("close.svg");
|
|
26
|
+
const button = new Sprite(icon);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The SVG is rasterized to a bitmap via the browser's native SVG-to-image pipeline, then uploaded as a `Texture`. Rendering is batched just like a regular sprite. Scaling up beyond the rasterized resolution pixelates; the rasterization happens once.
|
|
30
|
+
|
|
31
|
+
### Graphics mode
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const context = await Assets.load({
|
|
35
|
+
src: "logo.svg",
|
|
36
|
+
data: { parseAsGraphicsContext: true },
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const small = new Graphics(context);
|
|
40
|
+
small.scale.set(0.5);
|
|
41
|
+
|
|
42
|
+
const large = new Graphics(context);
|
|
43
|
+
large.scale.set(3);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The SVG is parsed into a `GraphicsContext` (a compiled list of fill/stroke instructions). Both `Graphics` instances share the same context; cheap, and both stay crisp at any scale.
|
|
47
|
+
|
|
48
|
+
### Resolution for sharper texture mode
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const icon = await Assets.load({
|
|
52
|
+
src: "icon.svg",
|
|
53
|
+
data: { resolution: 2 },
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For texture mode, you can pass `resolution` in `data` to rasterize at a higher density. Pairs with `autoGenerateMipmaps` for smooth downscaling. Doesn't apply in Graphics mode.
|
|
58
|
+
|
|
59
|
+
### Global default
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { loadSvg } from "pixi.js";
|
|
63
|
+
|
|
64
|
+
loadSvg.config.parseAsGraphicsContext = true;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Flip the default mode globally. Any subsequent `Assets.load('*.svg')` call parses as Graphics unless overridden in the asset's `data` options.
|
|
68
|
+
|
|
69
|
+
### What Graphics mode parses
|
|
70
|
+
|
|
71
|
+
Graphics mode reads `<path>` (including `fill-rule="evenodd"` holes), `<rect>`, `<circle>`, `<ellipse>`, `<line>`, `<polygon>`, `<polyline>`, and `<g>`. Styling comes from the `fill`, `stroke`, `stroke-width`, `fill-opacity`, `stroke-opacity`, and `opacity` attributes or inline `style="..."`. Fills and strokes can reference `<linearGradient>` and `<radialGradient>` definitions through `url(#id)`; `gradientUnits` and percentage coordinates are honored. Not supported: `transform` attributes, `<style>` blocks, `stroke-dasharray`/`stroke-linecap`/`stroke-linejoin`, `gradientTransform`, `spreadMethod`, `stop-opacity`, `<text>`, `<image>`, `<use>`, `<clipPath>`, `<mask>`, `<pattern>`, and filters. Unsupported elements are skipped with a console warning. Texture mode has none of these limits because the browser rasterizes the file.
|
|
72
|
+
|
|
73
|
+
### When to use which mode
|
|
74
|
+
|
|
75
|
+
| Mode | Best for | Cost |
|
|
76
|
+
| ----------------------------------------- | ------------------------------------------------- | -------------------------------------------------------------- |
|
|
77
|
+
| Texture (default) | Icons at a known size, backgrounds, complex SVGs | One-time rasterization; fast per-frame; pixelates when scaled |
|
|
78
|
+
| Graphics (`parseAsGraphicsContext: true`) | Scalable icons, UI elements, runtime modification | Higher initial parse cost; crisp at any scale; shared contexts |
|
|
79
|
+
|
|
80
|
+
If you need the same SVG at multiple sizes, Graphics mode is usually faster because you parse once and scale cheaply. If you have one fixed-size SVG, texture mode is simpler and batches with other sprites.
|
|
81
|
+
|
|
82
|
+
## Common Mistakes
|
|
83
|
+
|
|
84
|
+
### [HIGH] Expecting scalability in texture mode
|
|
85
|
+
|
|
86
|
+
Wrong:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const icon = await Assets.load("icon.svg");
|
|
90
|
+
const sprite = new Sprite(icon);
|
|
91
|
+
sprite.scale.set(5); // pixelates
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Correct (if you need scaling):
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const context = await Assets.load({
|
|
98
|
+
src: "icon.svg",
|
|
99
|
+
data: { parseAsGraphicsContext: true },
|
|
100
|
+
});
|
|
101
|
+
const graphic = new Graphics(context);
|
|
102
|
+
graphic.scale.set(5); // crisp
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or rasterize at higher resolution:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const icon = await Assets.load({
|
|
109
|
+
src: "icon.svg",
|
|
110
|
+
data: { resolution: 5 },
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Texture mode is frozen at rasterization time. Use Graphics mode or high `resolution` when the final size isn't known upfront.
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
### [MEDIUM] External references in SVG files
|
|
118
|
+
|
|
119
|
+
SVGs that reference external images via `<image href="...">` may fail to load if the reference is cross-origin without CORS headers. Inline the image data as base64 or serve everything from the same origin.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
### [MEDIUM] CSS in `<style>` elements
|
|
123
|
+
|
|
124
|
+
Graphics mode does not read `<style>` blocks or class selectors at all; only presentation attributes and inline `style="..."` are parsed, so class-styled shapes render with the default black fill. Move the styling inline, or use texture mode for full CSS fidelity.
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
## API Reference
|
|
128
|
+
|
|
129
|
+
- [Assets](https://pixijs.download/release/docs/assets.Assets.html.md)
|
|
130
|
+
- [LoadSVGConfig](https://pixijs.download/release/docs/assets.LoadSVGConfig.html.md)
|
|
131
|
+
- [Graphics](https://pixijs.download/release/docs/scene.Graphics.html.md)
|
|
132
|
+
- [GraphicsContext](https://pixijs.download/release/docs/scene.GraphicsContext.html.md)
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Video Textures
|
|
2
|
+
|
|
3
|
+
PixiJS loads videos through `Assets.load()` and returns a regular `Texture`. Pass the texture to a `Sprite` and it paints the current video frame each render. Use video textures for backgrounds, cutscenes, or any animated surface driven by a video source.
|
|
4
|
+
|
|
5
|
+
Supported extensions: `.mp4`, `.m4v`, `.webm`, `.ogg`, `.ogv`, `.h264`, `.avi`, `.mov`. Browser support varies; always provide a fallback format.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const videoTex = await Assets.load("intro.mp4");
|
|
11
|
+
const sprite = new Sprite(videoTex);
|
|
12
|
+
app.stage.addChild(sprite);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The returned texture wraps a `VideoSource`. The video starts playing automatically unless you set `autoPlay: false` in the `data` options.
|
|
16
|
+
|
|
17
|
+
## Core Patterns
|
|
18
|
+
|
|
19
|
+
### Load options via `data`
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const texture = await Assets.load({
|
|
23
|
+
src: "city.mp4",
|
|
24
|
+
data: {
|
|
25
|
+
autoPlay: false,
|
|
26
|
+
loop: true,
|
|
27
|
+
muted: true,
|
|
28
|
+
preload: true,
|
|
29
|
+
playsinline: true,
|
|
30
|
+
updateFPS: 30,
|
|
31
|
+
alphaMode: "premultiply-alpha-on-upload",
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`data` accepts `VideoSourceOptions` fields. Defaults come from `VideoSource.defaultOptions`.
|
|
37
|
+
|
|
38
|
+
| Option | Default | Purpose |
|
|
39
|
+
| ------------- | ---------------------- | ---------------------------------------------------------- |
|
|
40
|
+
| `autoLoad` | `true` | Start downloading the video as soon as it's assigned |
|
|
41
|
+
| `autoPlay` | `true` | Start playing once `canplay` fires |
|
|
42
|
+
| `loop` | `false` | Restart at the end |
|
|
43
|
+
| `muted` | `true` | Required for autoplay on most browsers |
|
|
44
|
+
| `playsinline` | `true` | Prevents iOS fullscreen takeover |
|
|
45
|
+
| `preload` | `false` | Await `canplaythrough` before resolving |
|
|
46
|
+
| `updateFPS` | `0` | Texture update rate. `0` updates every render frame |
|
|
47
|
+
| `crossorigin` | `true` | CORS mode for cross-origin URLs |
|
|
48
|
+
| `alphaMode` | auto-detected | `'no-premultiply-alpha'` for straight alpha |
|
|
49
|
+
| `mime` | derived from extension | Force a specific MIME type when the URL lacks an extension |
|
|
50
|
+
|
|
51
|
+
### Format fallback
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
Assets.add({
|
|
55
|
+
alias: "clip",
|
|
56
|
+
src: "clip.{webm,mp4}",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const texture = await Assets.load("clip");
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
List multiple formats so the resolver picks the first one the browser supports. WebM and MP4 together cover all current browsers.
|
|
63
|
+
|
|
64
|
+
### Mobile autoplay
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const texture = await Assets.load({
|
|
68
|
+
src: "ad.mp4",
|
|
69
|
+
data: {
|
|
70
|
+
muted: true,
|
|
71
|
+
playsinline: true,
|
|
72
|
+
autoPlay: true,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
iOS and mobile Chrome only autoplay muted, inline video. Set both `muted: true` and `playsinline: true` or playback stalls on the first frame until the user taps.
|
|
78
|
+
|
|
79
|
+
### Manual playback control
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const texture = await Assets.load({
|
|
83
|
+
src: "boss-fight.mp4",
|
|
84
|
+
data: { autoPlay: false, preload: true },
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const videoSource = texture.source as VideoSource;
|
|
88
|
+
|
|
89
|
+
startButton.on("pointertap", () => {
|
|
90
|
+
videoSource.resource.play();
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
With `autoPlay: false`, grab the underlying `VideoSource` from `texture.source` and call `.play()`, `.pause()`, or `.currentTime =` on its `resource` (the `HTMLVideoElement`). Pair with `preload: true` to guarantee the first frame is uploaded before you call `play()`.
|
|
95
|
+
|
|
96
|
+
### Updating at a fixed rate
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
await Assets.load({
|
|
100
|
+
src: "background.mp4",
|
|
101
|
+
data: { updateFPS: 15 },
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`updateFPS` caps how often the GPU texture re-uploads from the video element. `0` re-uploads every render tick (smoothest; highest cost). `15` caps it to 15 uploads per second, which saves bandwidth on static-ish video backgrounds.
|
|
106
|
+
|
|
107
|
+
## Forcing the video parser
|
|
108
|
+
|
|
109
|
+
If your video URL lacks an extension (e.g., a CDN signed URL or a blob), the loader can't pick a parser by test. Force it with the top-level `parser` field:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
const texture = await Assets.load({
|
|
113
|
+
src: "https://cdn.example.com/stream/abc123",
|
|
114
|
+
parser: "video",
|
|
115
|
+
data: { mime: "video/mp4" },
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
See the main `SKILL.md` section on "Forcing a parser with `parser`" for the full list of parser IDs.
|
|
120
|
+
|
|
121
|
+
## Common Mistakes
|
|
122
|
+
|
|
123
|
+
### [HIGH] Autoplay without mute on mobile
|
|
124
|
+
|
|
125
|
+
Wrong:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
await Assets.load({ src: "ad.mp4", data: { autoPlay: true } });
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Correct:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
await Assets.load({
|
|
135
|
+
src: "ad.mp4",
|
|
136
|
+
data: { autoPlay: true, muted: true, playsinline: true },
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Mobile browsers block autoplay with sound. The promise resolves, but the video stays frozen on frame 0 until the user interacts.
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### [MEDIUM] Expecting sprite.texture to update itself
|
|
144
|
+
|
|
145
|
+
The `Sprite` reflects the current video frame automatically because `VideoSource` re-uploads on every render. You don't need to call `update()` yourself. If playback looks frozen, check that the underlying video element is actually playing (`videoSource.resource.paused` should be `false`).
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### [MEDIUM] Missing CORS for cross-origin video
|
|
149
|
+
|
|
150
|
+
Video served from another origin without `Access-Control-Allow-Origin` headers taints the canvas and most WebGL operations (`readPixels`, snapshots) fail silently. Either serve with CORS headers or pass `data: { crossorigin: false }` and accept that the texture can't be extracted.
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
## API Reference
|
|
154
|
+
|
|
155
|
+
- [VideoSource](https://pixijs.download/release/docs/rendering.VideoSource.html.md)
|
|
156
|
+
- [VideoSourceOptions](https://pixijs.download/release/docs/rendering.VideoSourceOptions.html.md)
|
|
157
|
+
- [loadVideoTextures](https://pixijs.download/release/docs/assets.loadVideoTextures.html.md)
|
|
158
|
+
- [Assets](https://pixijs.download/release/docs/assets.Assets.html.md)
|