pixijs-core-concepts
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFoundational 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-conceptsPixiJS v8将像素渲染到屏幕的基础模型:渲染器决定使用哪个GPU后端,渲染循环驱动每帧的工作,环境层使库适配浏览器、Web Worker或SSR上下文。关于场景图本身(Containers、transforms、destroy),请查看。
pixijs-scene-core-conceptsQuick Start
快速入门
ts
console.log(app.renderer.name); // 'webgl' | 'webgpu' | 'canvas'
app.ticker.add((ticker) => {
sprite.rotation += 0.01 * ticker.deltaTime;
});
const tex = app.renderer.extract.texture({ target: app.stage });
app.renderer.render({ container: app.stage });app.rendererWebGLRendererWebGPURendererCanvasRendererautoDetectRendererrenderer.render()autoStart: falseApplication.init({ preference })pixijs-applicationRelated skills: (Application construction and lifecycle), (per-frame logic, priorities, FPS capping), (Web Worker, SSR, strict CSP), (writing a RenderPipe), (scene graph basics).
pixijs-applicationpixijs-tickerpixijs-environmentspixijs-custom-renderingpixijs-scene-core-conceptsts
console.log(app.renderer.name); // 'webgl' | 'webgpu' | 'canvas'
app.ticker.add((ticker) => {
sprite.rotation += 0.01 * ticker.deltaTime;
});
const tex = app.renderer.extract.texture({ target: app.stage });
app.renderer.render({ container: app.stage });app.rendererautoDetectRendererWebGLRendererWebGPURendererCanvasRendererrenderer.render()autoStart: falseApplication.init({ preference })pixijs-application相关技能: (应用构建与生命周期)、(每帧逻辑、优先级、FPS限制)、(Web Worker、SSR、严格CSP)、(编写RenderPipe)、(场景图基础)。
pixijs-applicationpixijs-tickerpixijs-environmentspixijs-custom-renderingpixijs-scene-core-conceptsTopics
主题
| Topic | Reference | When |
|---|---|---|
| Choosing a backend | references/renderers.md | Preference forms, per-renderer options, systems and pipes |
| Per-frame execution | references/render-loop.md | Priority order, time units, manual rendering |
For deep dives into any single topic, open the corresponding reference file. Non-browser targets (, , custom adapters, strict CSP) are covered in the skill.
DOMAdapterWebWorkerAdapterpixijs-environments| 主题 | 参考文档 | 适用场景 |
|---|---|---|
| 选择后端 | references/renderers.md | 偏好设置、各渲染器选项、系统与管道 |
| 每帧执行逻辑 | references/render-loop.md | 优先级顺序、时间单位、手动渲染 |
如需深入了解任一主题,请打开对应的参考文档。非浏览器目标(、、自定义适配器、严格CSP)在技能中讲解。
DOMAdapterWebWorkerAdapterpixijs-environmentsDecision guide
决策指南
- Setting up an Application? Start with . This skill explains what the renderer does under the hood.
pixijs-application - Choosing between WebGL and WebGPU? Use as your preference array. WebGPU is fastest where available; WebGL is the reliable fallback. See
['webgpu', 'webgl'].references/renderers.md - Running in a Web Worker? Set before
DOMAdapter.set(WebWorkerAdapter). See theapp.initskill for complete setup.pixijs-environments - Need manual control over when rendering happens? Set and call
autoStart: falsefrom your own loop. Seeapp.renderer.render(app.stage).references/render-loop.md - Integrating with a physics library? Add your update at so physics runs before the render at
UPDATE_PRIORITY.HIGH. SeeLOW.references/render-loop.md - Writing a custom renderable? Implement a . See
RenderPipeskill.pixijs-custom-rendering - Running under strict CSP? Import . See the
'pixi.js/unsafe-eval'skill.pixijs-environments
- 设置应用程序? 从开始。本技能解释渲染器的底层工作原理。
pixijs-application - 在WebGL和WebGPU之间选择? 使用作为你的偏好数组。WebGPU在支持的环境中速度最快;WebGL是可靠的备选方案。请查看
['webgpu', 'webgl']。references/renderers.md - 在Web Worker中运行? 在之前设置
app.init。完整设置请查看DOMAdapter.set(WebWorkerAdapter)技能。pixijs-environments - 需要手动控制渲染时机? 设置,并在你自己的循环中调用
autoStart: false。请查看app.renderer.render(app.stage)。references/render-loop.md - 与物理库集成? 在添加你的更新逻辑,这样物理计算会在
UPDATE_PRIORITY.HIGH优先级的渲染之前运行。请查看LOW。references/render-loop.md - 编写自定义可渲染对象? 实现一个。请查看
RenderPipe技能。pixijs-custom-rendering - 在严格CSP下运行? 导入。请查看
'pixi.js/unsafe-eval'技能。pixijs-environments
Quick concepts
核心概念
Renderer = systems + pipes
渲染器 = 系统 + 管道
Each renderer is composed of (lifecycle services: textures, buffers, state, filters, masks) and (per-renderable instruction builders: sprite, graphics, mesh, particle, text, tiling). Writing a custom renderable means implementing a and registering it via extensions.
SystemsRenderPipesRenderPipe每个渲染器由(生命周期服务:纹理、缓冲区、状态、滤镜、遮罩)和(每个可渲染对象的指令构建器:精灵、图形、网格、粒子、文本、平铺)组成。编写自定义可渲染对象意味着实现一个并通过扩展进行注册。
SystemsRenderPipesRenderPipeThe render loop
渲染循环
app.ticker.add(fn)TickerPluginapp.render()UPDATE_PRIORITY.LOWNORMALHIGHautoStart: falseapp.ticker.add(fn)UPDATE_PRIORITY.LOWapp.render()NORMALHIGHautoStart: falseEnvironments
环境适配
DOMAdapterDOMAdapter.set(WebWorkerAdapter)AdapterApplication.initDOMAdapterDOMAdapter.set(WebWorkerAdapter)AdapterApplication.initCommon Mistakes
常见错误
[HIGH] Accessing app.renderer before init() resolves
[高风险] 在init()完成前访问app.renderer
Wrong:
ts
const app = new Application();
app.init({ width: 800, height: 600 });
console.log(app.renderer.name); // undefined — init() is asyncCorrect:
ts
const app = new Application();
await app.init({ width: 800, height: 600 });
console.log(app.renderer.name); // 'webgl' | 'webgpu' | 'canvas'Application.init()app.rendererapp.canvasapp.screen错误示例:
ts
const app = new Application();
app.init({ width: 800, height: 600 });
console.log(app.renderer.name); // undefined — init()是异步的正确示例:
ts
const app = new Application();
await app.init({ width: 800, height: 600 });
console.log(app.renderer.name); // 'webgl' | 'webgpu' | 'canvas'Application.init()app.rendererapp.canvasapp.screen[HIGH] Setting DOMAdapter after Application.init
[高风险] 在Application.init之后设置DOMAdapter
Wrong:
ts
const app = new Application();
await app.init({ width: 800, height: 600 });
DOMAdapter.set(WebWorkerAdapter); // too late — init already allocated resourcesCorrect:
ts
DOMAdapter.set(WebWorkerAdapter);
const app = new Application();
await app.init({ width: 800, height: 600 });The adapter abstracts DOM calls the renderer makes during construction (canvas creation, image loading, fetch). Swap it before or the wrong adapter is baked into the renderer.
init()错误示例:
ts
const app = new Application();
await app.init({ width: 800, height: 600 });
DOMAdapter.set(WebWorkerAdapter); // 太晚了 — init已经分配了资源正确示例:
ts
DOMAdapter.set(WebWorkerAdapter);
const app = new Application();
await app.init({ width: 800, height: 600 });适配器会抽象渲染器在构建过程中进行的DOM调用(画布创建、图片加载、fetch)。必须在之前替换,否则错误的适配器会被固化到渲染器中。
init()[MEDIUM] Treating preference
as a guarantee
preference[中风险] 将preference
视为绝对保证
preferenceWrong:
ts
await app.init({ preference: "webgpu" });
// assume WebGPU is active
useWebGPUOnlyFeature(app.renderer);Correct:
ts
await app.init({ preference: "webgpu" });
if (app.renderer.name === "webgpu") {
useWebGPUOnlyFeature(app.renderer);
}preferencerenderer.name错误示例:
ts
await app.init({ preference: "webgpu" });
// 假设WebGPU已激活
useWebGPUOnlyFeature(app.renderer);正确示例:
ts
await app.init({ preference: "webgpu" });
if (app.renderer.name === "webgpu") {
useWebGPUOnlyFeature(app.renderer);
}preferencerenderer.name