@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
package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/constructor-options.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Constructor options (Container-inherited)
|
|
2
|
+
|
|
3
|
+
Prefer `new X({ ... })` over line-by-line property assignment when constructing Container-derived scene nodes.
|
|
4
|
+
|
|
5
|
+
## Before / after
|
|
6
|
+
|
|
7
|
+
Line-by-line:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const hero = new Sprite(texture);
|
|
11
|
+
hero.x = 100;
|
|
12
|
+
hero.y = 200;
|
|
13
|
+
hero.anchor.set(0.5);
|
|
14
|
+
hero.scale.set(2);
|
|
15
|
+
hero.rotation = Math.PI / 4;
|
|
16
|
+
hero.alpha = 0.8;
|
|
17
|
+
hero.tint = 0xff8800;
|
|
18
|
+
hero.label = "hero";
|
|
19
|
+
hero.zIndex = 10;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Options object:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const hero = new Sprite({
|
|
26
|
+
texture,
|
|
27
|
+
x: 100,
|
|
28
|
+
y: 200,
|
|
29
|
+
anchor: 0.5,
|
|
30
|
+
scale: 2,
|
|
31
|
+
rotation: Math.PI / 4,
|
|
32
|
+
alpha: 0.8,
|
|
33
|
+
tint: 0xff8800,
|
|
34
|
+
label: "hero",
|
|
35
|
+
zIndex: 10,
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Exceptions (line-by-line is fine here)
|
|
40
|
+
|
|
41
|
+
- Values calculated after construction — e.g., `sprite.position.set(app.screen.width / 2, app.screen.height / 2)` needs `app` to exist first.
|
|
42
|
+
- Properties that change at runtime and the change is the point of the example — e.g., `sprite.tint = damageColor` in a damage-flash demo.
|
|
43
|
+
- Objects received from elsewhere — you can't reconstruct them through a constructor options bag.
|
|
44
|
+
- `point.set(x, y)` / `scale.set(sx, sy)` for multi-coordinate batches where a single call reads better than two options keys.
|
|
45
|
+
|
|
46
|
+
For v7 to v8 migration of constructor patterns, see `pixijs-migration-v8`.
|
|
47
|
+
|
|
48
|
+
## Worked example
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const group = new Container({
|
|
52
|
+
// Transform
|
|
53
|
+
x: 100,
|
|
54
|
+
y: 200,
|
|
55
|
+
scale: { x: 2, y: 2 },
|
|
56
|
+
rotation: Math.PI / 4,
|
|
57
|
+
pivot: { x: 50, y: 50 },
|
|
58
|
+
skew: { x: 0, y: 0 },
|
|
59
|
+
// Display
|
|
60
|
+
alpha: 0.8,
|
|
61
|
+
tint: 0xff8800,
|
|
62
|
+
blendMode: "add",
|
|
63
|
+
visible: true,
|
|
64
|
+
renderable: true,
|
|
65
|
+
// Hierarchy
|
|
66
|
+
label: "world",
|
|
67
|
+
children: [background, player],
|
|
68
|
+
// Sorting & grouping
|
|
69
|
+
isRenderGroup: true,
|
|
70
|
+
sortableChildren: true,
|
|
71
|
+
zIndex: 10,
|
|
72
|
+
// Layout & bounds
|
|
73
|
+
boundsArea: new Rectangle(0, 0, 800, 600),
|
|
74
|
+
// Effects
|
|
75
|
+
filters: [new BlurFilter(2)],
|
|
76
|
+
mask: maskGraphics,
|
|
77
|
+
// Callbacks
|
|
78
|
+
onRender: (renderer) => {
|
|
79
|
+
/* per-frame logic */
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Transform
|
|
85
|
+
|
|
86
|
+
| Option | Type | Default | Description |
|
|
87
|
+
| ---------- | --------------------- | ----------------- | ----------------------------------------------------------------------------- |
|
|
88
|
+
| `alpha` | `number` | `1` | Opacity multiplied with parent alpha; 0 is fully transparent, 1 fully opaque. |
|
|
89
|
+
| `angle` | `number` | `0` | Rotation in degrees. Alias for `rotation` in radians. |
|
|
90
|
+
| `origin` | `PointData \| number` | `new Point(0, 0)` | Center of rotation and scaling without moving the node's position. |
|
|
91
|
+
| `pivot` | `PointData \| number` | `new Point(0, 0)` | Center of rotation, scaling, and skewing; reprojects position. |
|
|
92
|
+
| `position` | `PointData` | `new Point(0, 0)` | Position in parent-local coordinates. |
|
|
93
|
+
| `rotation` | `number` | `0` | Rotation in radians. |
|
|
94
|
+
| `scale` | `PointData \| number` | `new Point(1, 1)` | Local scale factor along each axis. |
|
|
95
|
+
| `skew` | `PointData` | `new Point(0, 0)` | Skew factor in radians along each axis. |
|
|
96
|
+
| `x` | `number` | `0` | Alias for `position.x`. |
|
|
97
|
+
| `y` | `number` | `0` | Alias for `position.y`. |
|
|
98
|
+
|
|
99
|
+
## Display
|
|
100
|
+
|
|
101
|
+
| Option | Type | Default | Description |
|
|
102
|
+
| ------------ | ------------- | ---------- | ------------------------------------------------------------------------ |
|
|
103
|
+
| `blendMode` | `BLEND_MODES` | `'normal'` | How this node composites against its target. |
|
|
104
|
+
| `renderable` | `boolean` | `true` | When false, skips rendering but still updates transforms. |
|
|
105
|
+
| `tint` | `ColorSource` | `0xFFFFFF` | Color multiplied into this node's output; `0xFFFFFF` is no tint. |
|
|
106
|
+
| `visible` | `boolean` | `true` | When false, skips both rendering and transform updates for this subtree. |
|
|
107
|
+
|
|
108
|
+
## Hierarchy
|
|
109
|
+
|
|
110
|
+
| Option | Type | Default | Description |
|
|
111
|
+
| ---------- | ----------- | ------- | ----------------------------------------------------------------------- |
|
|
112
|
+
| `children` | `C[]` | `[]` | Array of children to `addChild` after construction. |
|
|
113
|
+
| `label` | `string` | `null` | Instance label used by `getChildByLabel` / `getChildrenByLabel`. |
|
|
114
|
+
| `parent` | `Container` | `null` | Parent container; the new node is added as a child during construction. |
|
|
115
|
+
|
|
116
|
+
## Sorting & grouping
|
|
117
|
+
|
|
118
|
+
| Option | Type | Default | Description |
|
|
119
|
+
| ------------------ | --------- | ------- | ---------------------------------------------------------------------------------- |
|
|
120
|
+
| `isRenderGroup` | `boolean` | `false` | Marks this container as a render group; GPU-level transform for the whole subtree. |
|
|
121
|
+
| `sortableChildren` | `boolean` | `false` | Before rendering, re-sorts children by `zIndex`. |
|
|
122
|
+
| `zIndex` | `number` | `0` | Sort key used when the parent has `sortableChildren` enabled. |
|
|
123
|
+
|
|
124
|
+
## Layout & bounds
|
|
125
|
+
|
|
126
|
+
| Option | Type | Default | Description |
|
|
127
|
+
| ------------ | ----------- | ----------- | ------------------------------------------------------------- |
|
|
128
|
+
| `boundsArea` | `Rectangle` | `undefined` | Override bounds rectangle; skips recursive child measurement. |
|
|
129
|
+
| `height` | `number` | `0` | Requested height in pixels; internally assigns `scale.y`. |
|
|
130
|
+
| `width` | `number` | `0` | Requested width in pixels; internally assigns `scale.x`. |
|
|
131
|
+
|
|
132
|
+
## Effects
|
|
133
|
+
|
|
134
|
+
| Option | Type | Default | Description |
|
|
135
|
+
| --------- | ----------------------------- | ------- | ------------------------------------------------------------------------------- |
|
|
136
|
+
| `filters` | `Filter \| readonly Filter[]` | `null` | One filter or an array of filters applied to this subtree (WebGL/WebGPU only). |
|
|
137
|
+
| `mask` | `Container \| number \| null` | `null` | Mask display object or mask id; picks stencil/alpha/scissor/color mask by type. |
|
|
138
|
+
|
|
139
|
+
## Callbacks
|
|
140
|
+
|
|
141
|
+
| Option | Type | Default | Description |
|
|
142
|
+
| ---------- | ---------------------------------------- | ------- | ------------------------------------------------------------------ |
|
|
143
|
+
| `onRender` | `((renderer: Renderer) => void) \| null` | `null` | Per-frame callback invoked while this container is being rendered. |
|
|
144
|
+
|
|
145
|
+
## Advanced options and aliases
|
|
146
|
+
|
|
147
|
+
- `autoGarbageCollect` (@advanced, from `ViewContainerOptions`): leave at default unless you know why you need otherwise.
|
|
148
|
+
- `cacheAsTexture`: typed as a constructor option via `CacheAsTextureMixinConstructor` but is ACTUALLY A METHOD on the instance — `container.cacheAsTexture(true)`. Passing it as an options key is accepted but semantically wrong. Prefer the method.
|
|
149
|
+
- `setMask`: typed on `EffectsMixinConstructor` but is also a method, not data. Use `mask: ...` in options or call `setMask(...)` later.
|
|
150
|
+
- `interactive`: convenience boolean that maps to `eventMode`; `true` sets `eventMode = 'static'`, `false` sets `eventMode = 'passive'`. See `eventMode` for the full set of modes.
|
|
151
|
+
- `effects`: the `Container` constructor explicitly passes `effects: true` to `assignWithIgnore`, so passing this option is silently dropped. Not useful.
|
|
152
|
+
|
|
153
|
+
## See also
|
|
154
|
+
|
|
155
|
+
Events (`eventMode`, `hitArea`, `cursor`, `interactive*`, `on*` handlers), accessibility (`accessible*`, `tabIndex`, `accessibleTitle`, etc.), and culling (`cullable`, `cullArea`, `cullableChildren`) are ALSO valid constructor options via mixin extension on `ContainerOptions`. They are documented in their own skills: `pixijs-events`, `pixijs-accessibility`, `pixijs-performance`.
|
package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/container-hierarchy.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# Container Hierarchy
|
|
2
|
+
|
|
3
|
+
The PixiJS scene graph is a tree of `Container` subclasses rooted at `app.stage`. Every node has a single parent, zero or more children, and a local transform. Use this reference for mental model and fine-grained parent/child management; for full Container API (constructor options, lifecycle methods), see the top-level `pixijs-scene-container` skill.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const world = new Container({ label: "world" });
|
|
9
|
+
app.stage.addChild(world);
|
|
10
|
+
|
|
11
|
+
const hero = new Container({ label: "hero" });
|
|
12
|
+
hero.addChild(new Sprite(bodyTexture));
|
|
13
|
+
hero.addChild(new Sprite(weaponTexture));
|
|
14
|
+
world.addChild(hero);
|
|
15
|
+
|
|
16
|
+
const enemies = new Container({ label: "enemies" });
|
|
17
|
+
world.addChild(enemies);
|
|
18
|
+
|
|
19
|
+
enemies.addChild(new Sprite(enemyTexture), new Sprite(enemyTexture));
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Every display object in v8 is a `Container` subclass. Leaves (Sprite, Graphics, Text, Mesh, ParticleContainer, DOMContainer, GifSprite) have `allowChildren = false` and must not have children. Use a plain `Container` to group leaves.
|
|
23
|
+
|
|
24
|
+
## Core Patterns
|
|
25
|
+
|
|
26
|
+
### Add, remove, swap
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// Add (variadic, returns the first added child)
|
|
30
|
+
parent.addChild(child1, child2, child3);
|
|
31
|
+
|
|
32
|
+
// Insert at index
|
|
33
|
+
parent.addChildAt(child, 0);
|
|
34
|
+
|
|
35
|
+
// Remove
|
|
36
|
+
parent.removeChild(child);
|
|
37
|
+
parent.removeChildAt(0);
|
|
38
|
+
parent.removeChildren();
|
|
39
|
+
parent.removeChildren(0, 3); // first three
|
|
40
|
+
|
|
41
|
+
// Swap
|
|
42
|
+
parent.swapChildren(childA, childB);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`addChild` with an existing parent first removes the child from its old parent (no explicit `removeChild` needed). Returned value is the first added child for chaining.
|
|
46
|
+
|
|
47
|
+
When `addChildAt` moves a child that is **already** in the same container, the move is silent: no `added` / `removed` / `childAdded` / `childRemoved` events fire, because the parent-child relationship hasn't changed.
|
|
48
|
+
|
|
49
|
+
### Replacing a child
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
parent.replaceChild(oldChild, newChild);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`replaceChild` swaps `oldChild` for `newChild` at the same index and copies the old child's local transform (position, rotation, scale, etc.) onto the replacement. Use this when you want a drop-in replacement to inherit the old child's placement without copying fields by hand.
|
|
56
|
+
|
|
57
|
+
### Child queries
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const count = parent.children.length;
|
|
61
|
+
const first = parent.getChildAt(0);
|
|
62
|
+
const index = parent.getChildIndex(child);
|
|
63
|
+
|
|
64
|
+
const hero = parent.getChildByLabel("hero");
|
|
65
|
+
const heroDeep = parent.getChildByLabel("weapon", true); // recursive
|
|
66
|
+
|
|
67
|
+
const enemies = parent.getChildrenByLabel("enemy");
|
|
68
|
+
const waves = parent.getChildrenByLabel(/^wave-\d+/);
|
|
69
|
+
const buttonsDeep = parent.getChildrenByLabel("button", true);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`label` can be a `string` or a `RegExp` (e.g., `parent.getChildByLabel(/^hero-/)`). `getChildByLabel` returns the first match; `getChildrenByLabel` returns every match. Both walk the immediate children and recurse when the second argument is `true`. For more complex queries, iterate `parent.children` manually.
|
|
73
|
+
|
|
74
|
+
### Iterating children
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
for (const child of parent.children) {
|
|
78
|
+
child.alpha = 0.5;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
parent.children.forEach((child, i) => {
|
|
82
|
+
child.y = i * 32;
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`children` is a plain array. It's safe to iterate, but mutating it during iteration (via `addChild` / `removeChild`) is not; snapshot first with `[...parent.children]` if you need to modify the list.
|
|
87
|
+
|
|
88
|
+
### Reparenting with transform preservation
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
newParent.reparentChild(child);
|
|
92
|
+
|
|
93
|
+
newParent.reparentChildAt(child, 0);
|
|
94
|
+
|
|
95
|
+
newParent.reparentChild(childA, childB, childC);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`reparentChild` and `reparentChildAt` move children to a new parent while preserving their **world** transform, so the visuals don't jump. `reparentChild` appends to the end and accepts multiple children; `reparentChildAt` inserts at a specific index and accepts one child.
|
|
99
|
+
|
|
100
|
+
If you must do this manually (for example, to batch with other transform work), convert through `getGlobalPosition` and `toLocal`:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
const globalPos = child.getGlobalPosition();
|
|
104
|
+
newParent.addChild(child);
|
|
105
|
+
child.position = newParent.toLocal(globalPos);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Plain `addChild` keeps the local transform, which means the visual position changes; `reparentChild` is almost always what you want.
|
|
109
|
+
|
|
110
|
+
### Destroying sub-trees
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
branch.destroy({ children: true });
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`destroy()` unlinks a single node. `destroy({ children: true })` recursively tears down the entire sub-tree. Always use `{ children: true }` when removing a branch; otherwise you leak the child nodes and their textures.
|
|
117
|
+
|
|
118
|
+
### Label-based tree navigation
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
const panel = new Container({ label: "panel" });
|
|
122
|
+
panel.addChild(new Container({ label: "header" }));
|
|
123
|
+
panel.addChild(new Container({ label: "body" }));
|
|
124
|
+
|
|
125
|
+
const header = panel.getChildByLabel("header");
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Use `label` for debug tooling and light-weight tree navigation. Don't use it for hot-path code; the `getChildByLabel` walk is O(n) per call.
|
|
129
|
+
|
|
130
|
+
### Lifecycle events
|
|
131
|
+
|
|
132
|
+
Containers emit events for hierarchy changes, visibility changes, and destruction.
|
|
133
|
+
|
|
134
|
+
**Parent-side events** fire on the container whose children changed:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
group.on("childAdded", (child, parent, index) => {
|
|
138
|
+
/* ... */
|
|
139
|
+
});
|
|
140
|
+
group.on("childRemoved", (child, parent, index) => {
|
|
141
|
+
/* ... */
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Child-side events** fire on the child itself when its parent changes:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
sprite.on("added", (parent) => {
|
|
149
|
+
/* ... */
|
|
150
|
+
});
|
|
151
|
+
sprite.on("removed", (oldParent) => {
|
|
152
|
+
/* ... */
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Property and lifecycle events:**
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
container.on("visibleChanged", (visible) => {
|
|
160
|
+
/* ... */
|
|
161
|
+
});
|
|
162
|
+
container.on("destroyed", (container) => {
|
|
163
|
+
/* ... */
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`visibleChanged` fires whenever `container.visible` flips. `destroyed` fires inside `destroy()` after internal cleanup but before listeners are removed. By the time `destroyed` runs, `position`, `scale`, `pivot`, `origin`, `skew`, and `parent` have already been nulled, and `children` has been emptied (length 0, but the array reference itself is not nulled). Capture any container state you need **before** calling `destroy()`, not inside the event handler.
|
|
168
|
+
|
|
169
|
+
## Common Mistakes
|
|
170
|
+
|
|
171
|
+
### [CRITICAL] Adding children to a leaf
|
|
172
|
+
|
|
173
|
+
Wrong:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
sprite.addChild(otherSprite);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Correct:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const group = new Container();
|
|
183
|
+
group.addChild(sprite, otherSprite);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Sprite, Graphics, Text, Mesh, ParticleContainer, DOMContainer, and GifSprite all set `allowChildren = false`. Adding children logs a deprecation warning and will become a hard error. Use a plain `Container` to group.
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
### [HIGH] Destroying the parent without `children: true`
|
|
190
|
+
|
|
191
|
+
Wrong:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
levelContainer.destroy();
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Correct:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
levelContainer.destroy({ children: true });
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Plain `destroy()` only removes the parent. Its children become orphans; still in memory, still referencing textures. For a clean teardown, always pass `{ children: true }`, and include `texture: true` / `textureSource: true` when you also want to release GPU memory.
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
### [MEDIUM] Mutating `children` during iteration
|
|
207
|
+
|
|
208
|
+
Wrong:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
parent.children.forEach((child) => {
|
|
212
|
+
if (shouldRemove(child)) parent.removeChild(child);
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Correct:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
for (const child of [...parent.children]) {
|
|
220
|
+
if (shouldRemove(child)) parent.removeChild(child);
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
`removeChild` splices the array, shifting indices. Iterating the live array misses elements or processes some twice. Snapshot before iterating.
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
## API Reference
|
|
228
|
+
|
|
229
|
+
- [Container](https://pixijs.download/release/docs/scene.Container.html.md)
|
|
230
|
+
- [ContainerOptions](https://pixijs.download/release/docs/scene.ContainerOptions.html.md)
|
|
231
|
+
- [ContainerChild](https://pixijs.download/release/docs/scene.ContainerChild.html.md)
|
|
232
|
+
- [ChildrenHelperMixin](https://pixijs.download/release/docs/scene.ChildrenHelperMixin.html.md)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# RenderLayer
|
|
2
|
+
|
|
3
|
+
`RenderLayer` decouples render order from the scene graph hierarchy. Objects keep their logical parent (for transforms) but render at the layer's position in the scene. Use layers to pull specific objects to a specific z-depth without reparenting; the classic "character is parented to the world, but draws on the UI overlay" problem.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const bgLayer = new RenderLayer();
|
|
9
|
+
const entityLayer = new RenderLayer();
|
|
10
|
+
const uiLayer = new RenderLayer();
|
|
11
|
+
|
|
12
|
+
app.stage.addChild(bgLayer, entityLayer, uiLayer);
|
|
13
|
+
|
|
14
|
+
const world = new Container();
|
|
15
|
+
app.stage.addChild(world);
|
|
16
|
+
|
|
17
|
+
const player = new Sprite(texture);
|
|
18
|
+
world.addChild(player); // logical parent for transforms
|
|
19
|
+
entityLayer.attach(player); // render position
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The player lives in `world` for transform purposes (so moving the world moves the player), but the renderer draws it in the order determined by `entityLayer`'s position in the stage.
|
|
23
|
+
|
|
24
|
+
## Core Patterns
|
|
25
|
+
|
|
26
|
+
### attach / detach
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
layer.attach(sprite);
|
|
30
|
+
layer.attach(sprite1, sprite2, sprite3);
|
|
31
|
+
|
|
32
|
+
layer.detach(sprite);
|
|
33
|
+
layer.detachAll();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Use `attach()` / `detach()` for layer membership; not `addChild` / `removeChild`. RenderLayer overrides the scene graph methods to throw errors.
|
|
37
|
+
|
|
38
|
+
### Sorted layers
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const sortedLayer = new RenderLayer({
|
|
42
|
+
sortableChildren: true,
|
|
43
|
+
sortFunction: (a, b) => a.position.y - b.position.y,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
sortedLayer.attach(sprite1, sprite2, sprite3);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Set `sortableChildren: true` on the layer (not the object) and optionally pass a custom `sortFunction`. The default sort is by `zIndex`. Common use: y-sort for 2D top-down games so objects draw in depth order based on world y-position.
|
|
50
|
+
|
|
51
|
+
### Manual sort
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const layer = new RenderLayer({ sortableChildren: false });
|
|
55
|
+
layer.attach(sprite1, sprite2, sprite3);
|
|
56
|
+
|
|
57
|
+
layer.sortRenderLayerChildren();
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
If you turn off automatic sorting, call `sortRenderLayerChildren()` manually when you want the sort to happen. Useful when the sort order changes less often than every frame.
|
|
61
|
+
|
|
62
|
+
### Layer + logical parent
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const world = new Container();
|
|
66
|
+
const hud = new RenderLayer();
|
|
67
|
+
app.stage.addChild(world, hud);
|
|
68
|
+
|
|
69
|
+
const player = new Sprite(playerTexture);
|
|
70
|
+
world.addChild(player);
|
|
71
|
+
hud.attach(player);
|
|
72
|
+
|
|
73
|
+
world.x = 100; // player still moves with world
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The player's transform chain goes through `world`; moving `world.x` moves the player visually. But the renderer places the player's draw call at `hud`'s position in the scene graph, so the player renders on top of everything else.
|
|
77
|
+
|
|
78
|
+
### Removing from scene graph auto-detaches
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
world.removeChild(player);
|
|
82
|
+
// player is automatically detached from entityLayer
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
When you remove an object from its scene graph parent (via `removeChild`), the render layer attachment is cleared automatically. Re-adding the object to a scene graph parent does NOT re-attach it; you must call `layer.attach(player)` again.
|
|
86
|
+
|
|
87
|
+
## Common Mistakes
|
|
88
|
+
|
|
89
|
+
### [CRITICAL] Using `addChild` on a RenderLayer
|
|
90
|
+
|
|
91
|
+
Wrong:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const layer = new RenderLayer();
|
|
95
|
+
layer.addChild(sprite);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Correct:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
const layer = new RenderLayer();
|
|
102
|
+
container.addChild(sprite);
|
|
103
|
+
layer.attach(sprite);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`RenderLayer` throws on `addChild`. The object still needs a real scene graph parent (via `addChild` on a Container) for transforms; use `layer.attach()` to control render order.
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### [HIGH] Layer and attached children in different render groups
|
|
110
|
+
|
|
111
|
+
Wrong:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const renderGroup = new Container({ isRenderGroup: true });
|
|
115
|
+
const layer = new RenderLayer();
|
|
116
|
+
|
|
117
|
+
renderGroup.addChild(sprite);
|
|
118
|
+
app.stage.addChild(layer);
|
|
119
|
+
layer.attach(sprite);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Correct:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const renderGroup = new Container({ isRenderGroup: true });
|
|
126
|
+
const layer = new RenderLayer();
|
|
127
|
+
|
|
128
|
+
renderGroup.addChild(sprite);
|
|
129
|
+
renderGroup.addChild(layer);
|
|
130
|
+
layer.attach(sprite);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
A layer and the objects it attaches must be in the same render group. Otherwise the attached child renders without its correct transform composition.
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
### [MEDIUM] Expecting parent filters to apply to layer children
|
|
137
|
+
|
|
138
|
+
Filters on an ancestor Container are applied by capturing the container's children into a texture via push/pop. Layer-attached children skip this capture; they're collected separately and drawn at the layer's position. If you need a filter on a layer-attached object, apply the filter directly to the object (not the ancestor).
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
## API Reference
|
|
142
|
+
|
|
143
|
+
- [RenderLayer](https://pixijs.download/release/docs/scene.RenderLayer.html.md)
|
|
144
|
+
- [RenderLayerOptions](https://pixijs.download/release/docs/scene.RenderLayerOptions.html.md)
|
|
145
|
+
- [Container](https://pixijs.download/release/docs/scene.Container.html.md)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Masking
|
|
2
|
+
|
|
3
|
+
Clip display objects with PixiJS masks. PixiJS supports four mask types: AlphaMask (sprite-based), StencilMask (Graphics/Container-based via the stencil buffer), ScissorMask (axis-aligned rectangle), and ColorMask (bit-mask on channels).
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const photoGroup = new Container();
|
|
9
|
+
photoGroup.addChild(new Sprite(await Assets.load("photo.png")));
|
|
10
|
+
|
|
11
|
+
const mask = new Graphics().circle(100, 100, 80).fill(0xffffff);
|
|
12
|
+
photoGroup.mask = mask;
|
|
13
|
+
photoGroup.addChild(mask);
|
|
14
|
+
|
|
15
|
+
app.stage.addChild(photoGroup);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
A mask should live in the scene graph of the masked object's parent (typically as a child of the masked Container) so its transform tracks the masked subtree. Sprites, Text, and other leaves cannot hold the mask as a child (`allowChildren = false`); wrap them in a `Container` as shown above.
|
|
19
|
+
|
|
20
|
+
Set `container.mask` to a display object. PixiJS automatically selects the mask type based on what you assign.
|
|
21
|
+
|
|
22
|
+
## Core Patterns
|
|
23
|
+
|
|
24
|
+
### Mask type selection
|
|
25
|
+
|
|
26
|
+
PixiJS picks the mask type automatically based on the mask object:
|
|
27
|
+
|
|
28
|
+
| Mask object | Type used | Cost | Notes |
|
|
29
|
+
| --------------------- | ----------- | --------- | ------------------------------- |
|
|
30
|
+
| Graphics or Container | StencilMask | Medium | Uses stencil buffer |
|
|
31
|
+
| Sprite | AlphaMask | Expensive | Uses filter pipeline internally |
|
|
32
|
+
| Number (e.g., `0xF`) | ColorMask | Cheapest | Bitmask on RGBA channels |
|
|
33
|
+
|
|
34
|
+
Performance hierarchy: ColorMask (cheapest) < StencilMask < AlphaMask (most expensive). Choose the simplest mask that achieves the visual result.
|
|
35
|
+
|
|
36
|
+
Note: `ScissorMask` exists in the codebase but is not auto-selected by the mask system. Only `AlphaMask`, `StencilMask`, and `ColorMask` are registered as mask effects.
|
|
37
|
+
|
|
38
|
+
### Stencil mask (Graphics-based)
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const container = new Container();
|
|
42
|
+
const mask = new Graphics().roundRect(0, 0, 200, 150, 20).fill(0xffffff);
|
|
43
|
+
|
|
44
|
+
container.mask = mask;
|
|
45
|
+
container.addChild(mask);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The mask Graphics should be a child of the masked container (or share the same coordinate space). The fill color doesn't matter; only the shape is used.
|
|
49
|
+
|
|
50
|
+
### Alpha mask (Sprite-based)
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const maskTexture = await Assets.load("gradient-mask.png");
|
|
54
|
+
const maskSprite = new Sprite(maskTexture);
|
|
55
|
+
|
|
56
|
+
const photoGroup = new Container();
|
|
57
|
+
photoGroup.addChild(new Sprite(await Assets.load("photo.png")));
|
|
58
|
+
photoGroup.mask = maskSprite;
|
|
59
|
+
photoGroup.addChild(maskSprite);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Alpha masks use the **red channel** of the sprite texture by default to control visibility. High red value = fully visible, zero red = hidden. This is the most expensive mask type because it uses the filter pipeline internally.
|
|
63
|
+
|
|
64
|
+
### Mask channel selection
|
|
65
|
+
|
|
66
|
+
By default, sprite (alpha) masks read the red channel. If your mask texture uses transparency instead (e.g., a PNG with an alpha gradient), switch to the alpha channel via `setMask`:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const maskSprite = new Sprite(await Assets.load("alpha-gradient.png"));
|
|
70
|
+
|
|
71
|
+
const photoGroup = new Container();
|
|
72
|
+
photoGroup.addChild(new Sprite(await Assets.load("photo.png")));
|
|
73
|
+
photoGroup.setMask({ mask: maskSprite, channel: "alpha" });
|
|
74
|
+
photoGroup.addChild(maskSprite);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Available channels: `'red'` (default), `'alpha'`. This is useful when a single mask texture encodes different shapes in different channels.
|
|
78
|
+
|
|
79
|
+
### Inverse masking
|
|
80
|
+
|
|
81
|
+
Use `setMask` with `inverse: true` to show everything outside the mask shape:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
const holeMask = new Graphics().circle(100, 100, 80).fill(0xffffff);
|
|
85
|
+
const container = new Container();
|
|
86
|
+
container.setMask({ mask: holeMask, inverse: true });
|
|
87
|
+
container.addChild(holeMask);
|
|
88
|
+
|
|
89
|
+
const maskSprite = new Sprite(await Assets.load("mask.png"));
|
|
90
|
+
const photoGroup = new Container();
|
|
91
|
+
photoGroup.addChild(new Sprite(await Assets.load("photo.png")));
|
|
92
|
+
photoGroup.setMask({ mask: maskSprite, inverse: true });
|
|
93
|
+
photoGroup.addChild(maskSprite);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Both alpha and stencil masks support inverse on WebGL and WebGPU. Canvas2D does not support inverse stencil masks (it logs a warning and ignores the flag).
|
|
97
|
+
|
|
98
|
+
### Removing a mask
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
container.mask = null;
|
|
102
|
+
mask.destroy();
|
|
103
|
+
|
|
104
|
+
// Sprite masks: clear the mask before destroying its texture
|
|
105
|
+
photoGroup.mask = null;
|
|
106
|
+
maskSprite.destroy({ texture: true, textureSource: true });
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Always use `container.mask = null` to clear a mask. `setMask({ mask: null })` does not work due to an internal falsy check. Remove the mask reference before destroying the mask, the masked object, or (for sprite masks) the mask's texture. A sprite mask whose texture is destroyed while still assigned renders as empty and, in debug builds, logs `[MaskFilter] The mask texture was destroyed while the mask is still in use. Remove the mask before destroying its texture.`
|
|
110
|
+
|
|
111
|
+
## Common Mistakes
|
|
112
|
+
|
|
113
|
+
### [HIGH] Using cacheAsTexture with masks
|
|
114
|
+
|
|
115
|
+
The combination of `cacheAsTexture()` and masks is fragile. In Firefox, it can require a timeout between setting the mask and enabling caching. In other cases it fails silently. Avoid combining them when possible, or test thoroughly across browsers if needed.
|
|
116
|
+
|
|
117
|
+
### [MEDIUM] Using too many sprite masks
|
|
118
|
+
|
|
119
|
+
Sprite masks (AlphaMask) use the filter pipeline internally, making them the most expensive mask type. Using many of them simultaneously degrades performance significantly. Prefer stencil masks (Graphics shapes) or scissor masks (axis-aligned rectangles) when the visual result allows it.
|
|
120
|
+
|
|
121
|
+
Performance cost: Scissor (near zero) < Stencil (one extra draw) < Alpha (full filter pass)
|
|
122
|
+
|
|
123
|
+
## API Reference
|
|
124
|
+
|
|
125
|
+
- [AlphaMask](https://pixijs.download/release/docs/rendering.AlphaMask.html.md)
|
|
126
|
+
- [StencilMask](https://pixijs.download/release/docs/rendering.StencilMask.html.md)
|
|
127
|
+
- [ScissorMask](https://pixijs.download/release/docs/rendering.ScissorMask.html.md)
|
|
128
|
+
- [ColorMask](https://pixijs.download/release/docs/rendering.ColorMask.html.md)
|
|
129
|
+
- [MaskEffectManager](https://pixijs.download/release/docs/rendering.MaskEffectManager.html.md)
|