@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,215 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pixijs-blend-modes
|
|
3
|
+
description: "Use this skill when compositing display objects with blend modes in PixiJS v8. Covers standard modes (normal, add, multiply, screen, erase, min, max), advanced modes via pixi.js/advanced-blend-modes (color-burn, overlay, hard-light, etc.), batch-friendly ordering. Triggers on: blendMode, additive, multiply, screen, overlay, color-burn, color-dodge, advanced-blend-modes, glow, erase."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Set `container.blendMode` to composite display objects with GPU blend equations (standard modes) or filter-based advanced modes. Blend-mode transitions break render batches, so group like-mode siblings together.
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const light = new Sprite(await Assets.load("light.png"));
|
|
13
|
+
light.blendMode = "add";
|
|
14
|
+
app.stage.addChild(light);
|
|
15
|
+
|
|
16
|
+
const shadow = new Sprite(await Assets.load("shadow.png"));
|
|
17
|
+
shadow.blendMode = "multiply";
|
|
18
|
+
app.stage.addChild(shadow);
|
|
19
|
+
|
|
20
|
+
import "pixi.js/advanced-blend-modes";
|
|
21
|
+
const overlay = new Sprite(await Assets.load("overlay.png"));
|
|
22
|
+
overlay.blendMode = "color-burn";
|
|
23
|
+
app.stage.addChild(overlay);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Related skills:** `pixijs-filters` (advanced modes use the filter pipeline), `pixijs-performance` (batching with blend modes), `pixijs-color` (color manipulation).
|
|
27
|
+
|
|
28
|
+
## Core Patterns
|
|
29
|
+
|
|
30
|
+
### Standard blend modes
|
|
31
|
+
|
|
32
|
+
Standard modes are built in and use GPU blend equations directly:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { Sprite } from "pixi.js";
|
|
36
|
+
|
|
37
|
+
sprite.blendMode = "normal"; // standard alpha compositing (effective default at root)
|
|
38
|
+
sprite.blendMode = "add"; // additive (lighten, glow effects)
|
|
39
|
+
sprite.blendMode = "multiply"; // multiply (darken, shadow effects)
|
|
40
|
+
sprite.blendMode = "screen"; // screen (lighten, dodge effects)
|
|
41
|
+
sprite.blendMode = "erase"; // erase pixels from render target
|
|
42
|
+
sprite.blendMode = "none"; // no blending, overwrites destination
|
|
43
|
+
sprite.blendMode = "inherit"; // inherit from parent (this is the actual default value)
|
|
44
|
+
sprite.blendMode = "min"; // keeps minimum of source and destination (WebGL2+ only)
|
|
45
|
+
sprite.blendMode = "max"; // keeps maximum of source and destination (WebGL2+ only)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
These are hardware-accelerated and cheap. They do not require filters.
|
|
49
|
+
|
|
50
|
+
### Advanced blend modes
|
|
51
|
+
|
|
52
|
+
Advanced modes require an explicit import to register the extensions. On the WebGL renderer they also require `useBackBuffer: true` at init time, or PixiJS logs a warning and the blend silently falls back:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import "pixi.js/advanced-blend-modes";
|
|
56
|
+
import { Application, Sprite, Assets } from "pixi.js";
|
|
57
|
+
|
|
58
|
+
const app = new Application();
|
|
59
|
+
await app.init({ useBackBuffer: true }); // required for advanced modes on WebGL
|
|
60
|
+
|
|
61
|
+
const texture = await Assets.load("overlay.png");
|
|
62
|
+
const overlay = new Sprite(texture);
|
|
63
|
+
overlay.blendMode = "color-burn";
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Available advanced modes:
|
|
67
|
+
|
|
68
|
+
| Mode | Effect |
|
|
69
|
+
| -------------- | ----------------------------------------------- |
|
|
70
|
+
| `color-burn` | Darkens by increasing contrast |
|
|
71
|
+
| `color-dodge` | Brightens by decreasing contrast |
|
|
72
|
+
| `darken` | Keeps darker of two layers |
|
|
73
|
+
| `difference` | Absolute difference |
|
|
74
|
+
| `divide` | Divides bottom by top |
|
|
75
|
+
| `exclusion` | Similar to difference, lower contrast |
|
|
76
|
+
| `hard-light` | Multiply or screen based on top layer |
|
|
77
|
+
| `hard-mix` | High contrast threshold blend |
|
|
78
|
+
| `lighten` | Keeps lighter of two layers |
|
|
79
|
+
| `linear-burn` | Adds and subtracts to darken |
|
|
80
|
+
| `linear-dodge` | Adds layers together |
|
|
81
|
+
| `linear-light` | Linear burn or dodge based on top layer |
|
|
82
|
+
| `luminosity` | Luminosity of top, hue/saturation of bottom |
|
|
83
|
+
| `negation` | Inverted difference |
|
|
84
|
+
| `overlay` | Multiply or screen based on bottom layer |
|
|
85
|
+
| `pin-light` | Replaces based on lightness comparison |
|
|
86
|
+
| `saturation` | Saturation of top, hue/luminosity of bottom |
|
|
87
|
+
| `soft-light` | Gentle overlay effect |
|
|
88
|
+
| `subtract` | Subtracts top from bottom |
|
|
89
|
+
| `vivid-light` | Color burn or dodge based on top layer |
|
|
90
|
+
| `color` | Hue and saturation of top, luminosity of bottom |
|
|
91
|
+
|
|
92
|
+
You set advanced blend modes the same way as standard ones, via the `blendMode` property. They use filters internally, so they cost more than standard modes.
|
|
93
|
+
|
|
94
|
+
### Batch-friendly ordering
|
|
95
|
+
|
|
96
|
+
Different blend modes break the rendering batch. Order objects to minimize transitions:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { Container, Sprite } from "pixi.js";
|
|
100
|
+
|
|
101
|
+
const scene = new Container();
|
|
102
|
+
scene.addChild(screenSprite1); // 'screen'
|
|
103
|
+
scene.addChild(screenSprite2); // 'screen'
|
|
104
|
+
scene.addChild(normalSprite1); // 'normal'
|
|
105
|
+
scene.addChild(normalSprite2); // 'normal'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
2 draw calls. Alternating order (`screen, normal, screen, normal`) would produce 4.
|
|
109
|
+
|
|
110
|
+
## Common Mistakes
|
|
111
|
+
|
|
112
|
+
### [HIGH] Not importing advanced-blend-modes extension
|
|
113
|
+
|
|
114
|
+
Wrong:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { Sprite } from "pixi.js";
|
|
118
|
+
|
|
119
|
+
sprite.blendMode = "color-burn"; // silently falls back to normal
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Correct:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import "pixi.js/advanced-blend-modes";
|
|
126
|
+
import { Sprite } from "pixi.js";
|
|
127
|
+
|
|
128
|
+
sprite.blendMode = "color-burn";
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Advanced blend modes (color-burn, overlay, etc.) require the extension import. Without it, only standard modes (normal, add, multiply, screen) are available. The invalid mode silently falls back.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
### [MEDIUM] Mixing blend modes across adjacent objects
|
|
135
|
+
|
|
136
|
+
Different blend modes break the render batch. `screen / normal / screen / normal` produces 4 draw calls, while `screen / screen / normal / normal` produces 2. Sort children so objects with the same blend mode are adjacent.
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### [HIGH] Using the v7 BLEND_MODES enum
|
|
140
|
+
|
|
141
|
+
Wrong:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { BLEND_MODES } from "pixi.js";
|
|
145
|
+
|
|
146
|
+
sprite.blendMode = BLEND_MODES.ADD; // runtime error: BLEND_MODES is undefined
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Correct:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
sprite.blendMode = "add";
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
In v8, `BLEND_MODES` is a TypeScript type only (a union of string literals). There is no runtime enum export, so `BLEND_MODES.ADD` evaluates to accessing a property on `undefined`. Use the string form.
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
### [HIGH] Advanced blend modes without useBackBuffer
|
|
159
|
+
|
|
160
|
+
Wrong:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
import "pixi.js/advanced-blend-modes";
|
|
164
|
+
await app.init({
|
|
165
|
+
/* no useBackBuffer */
|
|
166
|
+
});
|
|
167
|
+
sprite.blendMode = "color-burn"; // logs a warning, falls back
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Correct:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import "pixi.js/advanced-blend-modes";
|
|
174
|
+
await app.init({ useBackBuffer: true });
|
|
175
|
+
sprite.blendMode = "color-burn";
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Advanced modes read from the back buffer. On WebGL, the blend silently falls back if the back buffer is not enabled. WebGPU enables the back buffer unconditionally.
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
### [MEDIUM] Advanced blend modes clipped or scaled on high-DPI renderers
|
|
182
|
+
|
|
183
|
+
Advanced blend modes are filter-based and use `Filter.defaultOptions`, whose resolution defaults to `1`. On a high-DPI render target the blended object can look clipped, scaled, or only partially applied.
|
|
184
|
+
|
|
185
|
+
Wrong:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import "pixi.js/advanced-blend-modes";
|
|
189
|
+
|
|
190
|
+
sprite.blendMode = "overlay"; // renders at resolution 1, can clip on retina
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Correct:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { Filter } from "pixi.js";
|
|
197
|
+
import "pixi.js/advanced-blend-modes";
|
|
198
|
+
|
|
199
|
+
Filter.defaultOptions.resolution = "inherit"; // set before creating affected objects
|
|
200
|
+
|
|
201
|
+
sprite.blendMode = "overlay";
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Setting `Filter.defaultOptions.resolution = "inherit"` makes advanced blend modes render at the render target's resolution. This costs more memory and runtime, so apply it where fidelity matters.
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
## API Reference
|
|
208
|
+
|
|
209
|
+
- [Container.blendMode](https://pixijs.download/release/docs/scene.Container.html.md)
|
|
210
|
+
- [OverlayBlend](https://pixijs.download/release/docs/filters.OverlayBlend.html.md)
|
|
211
|
+
- [ColorBurnBlend](https://pixijs.download/release/docs/filters.ColorBurnBlend.html.md)
|
|
212
|
+
- [ColorDodgeBlend](https://pixijs.download/release/docs/filters.ColorDodgeBlend.html.md)
|
|
213
|
+
- [HardLightBlend](https://pixijs.download/release/docs/filters.HardLightBlend.html.md)
|
|
214
|
+
- [SoftLightBlend](https://pixijs.download/release/docs/filters.SoftLightBlend.html.md)
|
|
215
|
+
- [DifferenceBlend](https://pixijs.download/release/docs/filters.DifferenceBlend.html.md)
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pixijs-color
|
|
3
|
+
description: "Use this skill when creating, converting, or manipulating colors in PixiJS v8. Covers Color class input formats (hex, CSS names, RGB/HSL objects, arrays, Uint8Array), conversion methods (toHex, toNumber, toArray, toRgba), component access, setAlpha/multiply/premultiply, Color.shared singleton. Triggers on: Color, ColorSource, hex, rgb, hsl, tint, premultiply, Color.shared, color conversion."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The `Color` class creates and converts colors for tints, fills, strokes, and anywhere PixiJS accepts a `ColorSource`. Most APIs accept raw hex/strings directly, so explicit `new Color(...)` is only needed when converting formats or manipulating values.
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const fillColor = new Color("#ff6600");
|
|
13
|
+
console.log(fillColor.toHex()); // '#ff6600'
|
|
14
|
+
console.log(fillColor.toNumber()); // 0xff6600
|
|
15
|
+
console.log(fillColor.toArray()); // [1, 0.4, 0, 1]
|
|
16
|
+
|
|
17
|
+
const g = new Graphics().rect(0, 0, 200, 100).fill(fillColor);
|
|
18
|
+
app.stage.addChild(g);
|
|
19
|
+
|
|
20
|
+
const sprite = Sprite.from("hero.png");
|
|
21
|
+
sprite.tint = "dodgerblue";
|
|
22
|
+
app.stage.addChild(sprite);
|
|
23
|
+
|
|
24
|
+
const t = Color.shared.setValue(0xffffff).multiply([1, 0.5, 0.5]).toNumber();
|
|
25
|
+
sprite.tint = t;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Related skills:** `pixijs-scene-graphics` (fill/stroke colors), `pixijs-scene-sprite` (tint), `pixijs-blend-modes` (compositing).
|
|
29
|
+
|
|
30
|
+
## Core Patterns
|
|
31
|
+
|
|
32
|
+
### Accepted input formats
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { Color } from "pixi.js";
|
|
36
|
+
|
|
37
|
+
// Hex integer
|
|
38
|
+
new Color(0xff0000);
|
|
39
|
+
|
|
40
|
+
// Hex strings
|
|
41
|
+
new Color("#ff0000");
|
|
42
|
+
new Color("#f00");
|
|
43
|
+
new Color("ff0000");
|
|
44
|
+
|
|
45
|
+
// CSS color names
|
|
46
|
+
new Color("red");
|
|
47
|
+
new Color("dodgerblue");
|
|
48
|
+
|
|
49
|
+
// RGB/RGBA objects (components 0-255)
|
|
50
|
+
new Color({ r: 255, g: 0, b: 0 });
|
|
51
|
+
new Color({ r: 255, g: 0, b: 0, a: 0.5 });
|
|
52
|
+
|
|
53
|
+
// HSL/HSLA objects
|
|
54
|
+
new Color({ h: 0, s: 100, l: 50 });
|
|
55
|
+
new Color({ h: 0, s: 100, l: 50, a: 0.5 });
|
|
56
|
+
|
|
57
|
+
// HSV/HSVA objects
|
|
58
|
+
new Color({ h: 0, s: 100, v: 100 });
|
|
59
|
+
|
|
60
|
+
// CSS strings
|
|
61
|
+
new Color("rgb(255, 0, 0)");
|
|
62
|
+
new Color("rgba(255, 0, 0, 0.5)");
|
|
63
|
+
new Color("hsl(0, 100%, 50%)");
|
|
64
|
+
|
|
65
|
+
// Normalized 0-1 arrays (Float32Array or plain arrays)
|
|
66
|
+
new Color([1, 0, 0]); // RGB
|
|
67
|
+
new Color([1, 0, 0, 0.5]); // RGBA
|
|
68
|
+
|
|
69
|
+
// Uint8 arrays (components 0-255)
|
|
70
|
+
new Color(new Uint8Array([255, 0, 0]));
|
|
71
|
+
new Color(new Uint8ClampedArray([255, 0, 0, 128]));
|
|
72
|
+
|
|
73
|
+
// 8-digit hex with alpha
|
|
74
|
+
new Color("#ff0000ff");
|
|
75
|
+
new Color("#f00f");
|
|
76
|
+
|
|
77
|
+
// Copy from another Color instance
|
|
78
|
+
const red = new Color("red");
|
|
79
|
+
const copy = new Color(red);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Conversion methods
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { Color } from "pixi.js";
|
|
86
|
+
|
|
87
|
+
const color = new Color("#ff6600");
|
|
88
|
+
|
|
89
|
+
color.toHex(); // '#ff6600'
|
|
90
|
+
color.toHexa(); // '#ff6600ff' (hex with alpha)
|
|
91
|
+
color.toNumber(); // 0xff6600
|
|
92
|
+
color.toArray(); // [1, 0.4, 0, 1] (normalized RGBA)
|
|
93
|
+
color.toRgbArray(); // [1, 0.4, 0] (normalized RGB, no alpha)
|
|
94
|
+
color.toRgbaString(); // 'rgba(255,102,0,1)'
|
|
95
|
+
color.toRgba(); // { r: 1, g: 0.4, b: 0, a: 1 }
|
|
96
|
+
color.toRgb(); // { r: 1, g: 0.4, b: 0 }
|
|
97
|
+
color.toUint8RgbArray(); // [255, 102, 0]
|
|
98
|
+
|
|
99
|
+
// setValue() is the chainable way to change a color's value
|
|
100
|
+
color.setValue(0xff0000).toHex(); // '#ff0000'
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Component access
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { Color } from "pixi.js";
|
|
107
|
+
|
|
108
|
+
const color = new Color("rgba(255, 128, 0, 0.8)");
|
|
109
|
+
|
|
110
|
+
color.red; // 1
|
|
111
|
+
color.green; // ~0.502
|
|
112
|
+
color.blue; // 0
|
|
113
|
+
color.alpha; // 0.8
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
All component getters return normalized 0-1 values.
|
|
117
|
+
|
|
118
|
+
### Manipulation
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { Color } from "pixi.js";
|
|
122
|
+
|
|
123
|
+
const color = new Color("red");
|
|
124
|
+
|
|
125
|
+
// Set alpha (chainable)
|
|
126
|
+
color.setAlpha(0.5);
|
|
127
|
+
|
|
128
|
+
// Multiply with another color (destructive, modifies in place)
|
|
129
|
+
color.multiply(0x808080);
|
|
130
|
+
|
|
131
|
+
// Premultiply alpha (destructive, RGB channels multiplied by alpha)
|
|
132
|
+
color.premultiply(0.8);
|
|
133
|
+
|
|
134
|
+
// Premultiply alpha only (RGB unchanged)
|
|
135
|
+
color.premultiply(0.8, false);
|
|
136
|
+
|
|
137
|
+
// Chain operations
|
|
138
|
+
new Color("white").setAlpha(0.5).multiply([0.8, 0.2, 0.2]);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`multiply()` and `premultiply()` are destructive; they modify the color and set `value` to null (original format is lost).
|
|
142
|
+
|
|
143
|
+
### Non-destructive premultiplied output
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { Color } from "pixi.js";
|
|
147
|
+
|
|
148
|
+
const color = new Color("red").setAlpha(0.5);
|
|
149
|
+
|
|
150
|
+
const packed = color.toPremultiplied(color.alpha); // 0x7F7F0000
|
|
151
|
+
const alphaOnly = color.toPremultiplied(color.alpha, false); // 0x7FFF0000
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`toPremultiplied(alpha, applyToRGB?)` returns a 32-bit `0xAARRGGBB` integer without mutating `this`. Use it in batchers and tint math where the source color must be reused. When `applyToRGB` is `false`, only the alpha byte is packed; the RGB stays at its full value.
|
|
155
|
+
|
|
156
|
+
### Reusing output buffers
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { Color } from "pixi.js";
|
|
160
|
+
|
|
161
|
+
const rgba = new Float32Array(4);
|
|
162
|
+
const rgb = new Float32Array(3);
|
|
163
|
+
const rgb8 = new Uint8Array(3);
|
|
164
|
+
|
|
165
|
+
app.ticker.add(() => {
|
|
166
|
+
Color.shared.setValue(sprite.tint).toArray(rgba).toRgbArray(rgb);
|
|
167
|
+
|
|
168
|
+
Color.shared.toUint8RgbArray(rgb8);
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`toArray(out?)`, `toRgbArray(out?)`, and `toUint8RgbArray(out?)` accept a reusable `number[]`, `Float32Array`, `Uint8Array`, or `Uint8ClampedArray` and write into it. Pass your own buffer in hot paths to avoid allocating per frame; omit the argument and the `Color` instance returns its internal cache array.
|
|
173
|
+
|
|
174
|
+
### Packing for GPU buffers
|
|
175
|
+
|
|
176
|
+
| Method | Returns |
|
|
177
|
+
| ------------------------ | ------------------------------------------------------------ |
|
|
178
|
+
| `toBgrNumber()` | 24-bit `0xBBGGRR` integer with R/B swapped |
|
|
179
|
+
| `toLittleEndianNumber()` | Same 24-bit swap, convenient for little-endian vertex writes |
|
|
180
|
+
|
|
181
|
+
Both are cheap and useful when emitting colors straight into packed vertex attributes.
|
|
182
|
+
|
|
183
|
+
### Color.shared for temporary operations
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
import { Color } from "pixi.js";
|
|
187
|
+
|
|
188
|
+
// One-off conversion without allocating a new Color
|
|
189
|
+
const hex = Color.shared.setValue("#ff6600").toNumber();
|
|
190
|
+
const arr = Color.shared.setValue(0xff0000).toArray();
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`Color.shared` is a singleton that avoids allocating a new `Color` on every call. This matters in hot paths like render loops or per-frame tint calculations where repeated `new Color()` creates GC pressure. Do not store references to it; other code may mutate it.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { Color } from "pixi.js";
|
|
197
|
+
|
|
198
|
+
// Good: reuse shared instance in a per-frame callback
|
|
199
|
+
app.ticker.add(() => {
|
|
200
|
+
const t = performance.now() / 1000;
|
|
201
|
+
sprite.tint = Color.shared
|
|
202
|
+
.setValue("white")
|
|
203
|
+
.multiply([Math.sin(t) * 0.5 + 0.5, 0.2, 0.8])
|
|
204
|
+
.toNumber();
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Validating input
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { Color } from "pixi.js";
|
|
212
|
+
|
|
213
|
+
Color.isColorLike("red"); // true
|
|
214
|
+
Color.isColorLike("#ff0000"); // true
|
|
215
|
+
Color.isColorLike(0xff0000); // true
|
|
216
|
+
Color.isColorLike([1, 0, 0]); // true
|
|
217
|
+
Color.isColorLike({ r: 1, g: 0, b: 0 }); // true
|
|
218
|
+
Color.isColorLike({ foo: 1 }); // false
|
|
219
|
+
Color.isColorLike(null); // false
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
`Color.isColorLike()` checks the structural shape (string, number, array, or recognized object). It doesn't validate that a string is a real CSS color name, nor that array values fall in range. Use it as a type guard before passing user input to `new Color()` or `setValue()`.
|
|
223
|
+
|
|
224
|
+
## Common Mistakes
|
|
225
|
+
|
|
226
|
+
### [MEDIUM] Expecting toRgba() to return 0-255 values
|
|
227
|
+
|
|
228
|
+
Wrong:
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import { Color } from "pixi.js";
|
|
232
|
+
|
|
233
|
+
const { r, g, b } = new Color({ r: 255, g: 128, b: 0 }).toRgba();
|
|
234
|
+
// r = 1, g = ~0.502, b = 0 (NOT 255, 128, 0)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Correct:
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
import { Color } from "pixi.js";
|
|
241
|
+
|
|
242
|
+
// Use toUint8RgbArray() for 0-255 output
|
|
243
|
+
const [r, g, b] = new Color({ r: 255, g: 128, b: 0 }).toUint8RgbArray();
|
|
244
|
+
// r = 255, g = 128, b = 0
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
RGB object _inputs_ use 0-255 range (`{ r: 255, g: 0, b: 0 }`), but all output methods (`toRgba()`, `toRgb()`, `toArray()`, `toRgbArray()`) normalize to 0-1. Use `toUint8RgbArray()` when you need 0-255 integers for CSS or external APIs.
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
### [MEDIUM] Using 0-255 range in color arrays
|
|
251
|
+
|
|
252
|
+
Wrong:
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
import { Color } from "pixi.js";
|
|
256
|
+
|
|
257
|
+
new Color([255, 0, 0]); // NOT red; values are interpreted as 0-1
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Correct:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
import { Color } from "pixi.js";
|
|
264
|
+
|
|
265
|
+
new Color([1, 0, 0]); // red via normalized array
|
|
266
|
+
new Color(0xff0000); // red via hex
|
|
267
|
+
new Color("red"); // red via CSS name
|
|
268
|
+
new Color(new Uint8Array([255, 0, 0])); // red via Uint8Array (0-255)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Plain number arrays (`number[]` and `Float32Array`) use normalized 0-1 range. `[255, 0, 0]` clamps to `[1, 0, 0]` because values are clamped, but `[200, 100, 50]` does not produce the expected color. Use `Uint8Array` or `Uint8ClampedArray` for 0-255 input.
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
### [MEDIUM] Using utils.string2hex or utils.hex2string
|
|
275
|
+
|
|
276
|
+
Wrong:
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
import { utils } from "pixi.js";
|
|
280
|
+
|
|
281
|
+
const hex = utils.string2hex("#ff0000");
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Correct:
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
import { Color } from "pixi.js";
|
|
288
|
+
|
|
289
|
+
const hex = new Color("#ff0000").toNumber();
|
|
290
|
+
const str = new Color(0xff0000).toHex();
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
The `utils` namespace was removed in v8. Use the `Color` class for all color conversions.
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
## API Reference
|
|
297
|
+
|
|
298
|
+
- [Color](https://pixijs.download/release/docs/color.Color.html.md)
|
|
299
|
+
- [ColorSource](https://pixijs.download/release/docs/color.ColorSource.html.md)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pixijs-core-concepts
|
|
3
|
+
description: "Use this skill when understanding how PixiJS v8 renders frames: the systems-and-pipes renderer, the render loop, and how the library adapts to different environments. Covers WebGLRenderer/WebGPURenderer/CanvasRenderer selection, renderer.render() pipeline, environment detection, rendering into RenderTextures and RenderTargets (flipY, mipLevel, layer, bind/push/pop, copyDepthTexture), WebGL context loss and WebGPU device loss recovery, and pointers to per-topic deep dives. Triggers on: renderer, WebGL, WebGPU, Canvas, render loop, render pipeline, systems, environments, autoDetectRenderer, RenderTexture, RenderTarget, render to texture, flipY, mipLevel, layer, 3D texture, depth slice, renderTarget.bind, copyToTexture, copyDepthTexture, depth-only, WebGLLoader, WebGPULoader, CanvasLoader, RendererLoader, lazy-load renderer systems, code splitting, context lost, webglcontextlost, device lost, GPUDevice.lost."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Foundational model for how PixiJS v8 gets pixels on the screen: the renderer decides which GPU backend to use, the render loop drives per-frame work, and the environment layer adapts the library to browser, Web Worker, or SSR contexts. For the scene graph itself (Containers, transforms, destroy), see `pixijs-scene-core-concepts`.
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
console.log(app.renderer.name); // 'webgl' | 'webgpu' | 'canvas'
|
|
13
|
+
|
|
14
|
+
app.ticker.add((ticker) => {
|
|
15
|
+
sprite.rotation += 0.01 * ticker.deltaTime;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const tex = app.renderer.extract.texture({ target: app.stage });
|
|
19
|
+
|
|
20
|
+
app.renderer.render({ container: app.stage });
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`app.renderer` is the `WebGLRenderer`, `WebGPURenderer`, or `CanvasRenderer` chosen by `autoDetectRenderer`. The TickerPlugin drives `renderer.render()` automatically; call it manually only with `autoStart: false`. Backend selection happens in `Application.init({ preference })`; see `pixijs-application` for setup.
|
|
24
|
+
|
|
25
|
+
**Related skills:** `pixijs-application` (Application construction and lifecycle), `pixijs-ticker` (per-frame logic, priorities, FPS capping), `pixijs-environments` (Web Worker, SSR, strict CSP), `pixijs-custom-rendering` (writing a RenderPipe), `pixijs-scene-core-concepts` (scene graph basics).
|
|
26
|
+
|
|
27
|
+
## Topics
|
|
28
|
+
|
|
29
|
+
| Topic | Reference | When |
|
|
30
|
+
| ------------------- | ------------------------------------------------------ | --------------------------------------------------------- |
|
|
31
|
+
| Choosing a backend | [references/renderers.md](references/renderers.md) | Preference forms, per-renderer options, systems and pipes |
|
|
32
|
+
| Per-frame execution | [references/render-loop.md](references/render-loop.md) | Priority order, time units, manual rendering |
|
|
33
|
+
|
|
34
|
+
For deep dives into any single topic, open the corresponding reference file. Non-browser targets (`DOMAdapter`, `WebWorkerAdapter`, custom adapters, strict CSP) are covered in the `pixijs-environments` skill.
|
|
35
|
+
|
|
36
|
+
## Decision guide
|
|
37
|
+
|
|
38
|
+
- **Setting up an Application?** Start with `pixijs-application`. This skill explains what the renderer does under the hood.
|
|
39
|
+
- **Choosing between WebGL and WebGPU?** Use `['webgpu', 'webgl']` as your preference array. WebGPU is fastest where available; WebGL is the reliable fallback. See `references/renderers.md`.
|
|
40
|
+
- **Running in a Web Worker?** Set `DOMAdapter.set(WebWorkerAdapter)` before `app.init`. See the `pixijs-environments` skill for complete setup.
|
|
41
|
+
- **Need manual control over when rendering happens?** Set `autoStart: false` and call `app.renderer.render(app.stage)` from your own loop. See `references/render-loop.md`.
|
|
42
|
+
- **Integrating with a physics library?** Add your update at `UPDATE_PRIORITY.HIGH` so physics runs before the render at `LOW`. See `references/render-loop.md`.
|
|
43
|
+
- **Writing a custom renderable?** Implement a `RenderPipe`. See `pixijs-custom-rendering` skill.
|
|
44
|
+
- **Rendering into a texture or a custom render target?** Pass `target` to `renderer.render()`, or build a `RenderTarget` with explicit color and depth attachments. See `references/renderers.md`.
|
|
45
|
+
- **Running under strict CSP?** Import `'pixi.js/unsafe-eval'`. See the `pixijs-environments` skill.
|
|
46
|
+
|
|
47
|
+
## Quick concepts
|
|
48
|
+
|
|
49
|
+
### Renderer = systems + pipes
|
|
50
|
+
|
|
51
|
+
Each renderer is composed of `Systems` (lifecycle services: textures, buffers, state, filters, masks) and `RenderPipes` (per-renderable instruction builders: sprite, graphics, mesh, particle, text, tiling). Writing a custom renderable means implementing a `RenderPipe` and registering it via extensions. Backend-specific systems and pipes can be dynamic-imported through a renderer loader extension (`WebGLLoader`, `WebGPULoader`, `CanvasLoader`); see `references/renderers.md`.
|
|
52
|
+
|
|
53
|
+
### The render loop
|
|
54
|
+
|
|
55
|
+
`app.ticker.add(fn)` registers a callback that runs every frame. The `TickerPlugin` registers `app.render()` at `UPDATE_PRIORITY.LOW`, so ticker callbacks at `NORMAL` or `HIGH` run before the draw. Disable the plugin with `autoStart: false` for manual control.
|
|
56
|
+
|
|
57
|
+
### Environments
|
|
58
|
+
|
|
59
|
+
`DOMAdapter` abstracts every DOM call PixiJS makes (canvas creation, image loading, fetch, XML parsing). Swap with `DOMAdapter.set(WebWorkerAdapter)` for Workers or implement a custom `Adapter` for Node/SSR. Must be done before `Application.init`.
|
|
60
|
+
|
|
61
|
+
## Common Mistakes
|
|
62
|
+
|
|
63
|
+
### [HIGH] Accessing app.renderer before init() resolves
|
|
64
|
+
|
|
65
|
+
Wrong:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const app = new Application();
|
|
69
|
+
app.init({ width: 800, height: 600 });
|
|
70
|
+
console.log(app.renderer.name); // undefined — init() is async
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Correct:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const app = new Application();
|
|
77
|
+
await app.init({ width: 800, height: 600 });
|
|
78
|
+
console.log(app.renderer.name); // 'webgl' | 'webgpu' | 'canvas'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`Application.init()` is async. `app.renderer`, `app.canvas`, and `app.screen` do not exist until after the promise resolves.
|
|
82
|
+
|
|
83
|
+
### [HIGH] Setting DOMAdapter after Application.init
|
|
84
|
+
|
|
85
|
+
Wrong:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const app = new Application();
|
|
89
|
+
await app.init({ width: 800, height: 600 });
|
|
90
|
+
DOMAdapter.set(WebWorkerAdapter); // too late — init already allocated resources
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Correct:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
DOMAdapter.set(WebWorkerAdapter);
|
|
97
|
+
const app = new Application();
|
|
98
|
+
await app.init({ width: 800, height: 600 });
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The adapter abstracts DOM calls the renderer makes during construction (canvas creation, image loading, fetch). Swap it before `init()` or the wrong adapter is baked into the renderer.
|
|
102
|
+
|
|
103
|
+
### [MEDIUM] Treating `preference` as a guarantee
|
|
104
|
+
|
|
105
|
+
Wrong:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
await app.init({ preference: "webgpu" });
|
|
109
|
+
// assume WebGPU is active
|
|
110
|
+
useWebGPUOnlyFeature(app.renderer);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Correct:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
await app.init({ preference: "webgpu" });
|
|
117
|
+
if (app.renderer.name === "webgpu") {
|
|
118
|
+
useWebGPUOnlyFeature(app.renderer);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`preference` is a hint, not a demand. If the browser lacks WebGPU support, PixiJS falls back to WebGL (or Canvas). Always branch on `renderer.name` for backend-specific code.
|
|
123
|
+
|
|
124
|
+
## API Reference
|
|
125
|
+
|
|
126
|
+
- [autoDetectRenderer](https://pixijs.download/release/docs/rendering.autoDetectRenderer.html.md)
|
|
127
|
+
- [AbstractRenderer](https://pixijs.download/release/docs/rendering.AbstractRenderer.html.md)
|
|
128
|
+
- [WebGLRenderer](https://pixijs.download/release/docs/rendering.WebGLRenderer.html.md)
|
|
129
|
+
- [WebGPURenderer](https://pixijs.download/release/docs/rendering.WebGPURenderer.html.md)
|
|
130
|
+
- [CanvasRenderer](https://pixijs.download/release/docs/rendering.CanvasRenderer.html.md)
|
|
131
|
+
- [Application](https://pixijs.download/release/docs/app.Application.html.md)
|
|
132
|
+
- [DOMAdapter](https://pixijs.download/release/docs/environment.DOMAdapter.html.md)
|