pixijs-application
Use this skill when creating and configuring a PixiJS v8 Application. Covers new Application() + async app.init() options (width, height, background, antialias, resolution, autoDensity, preference, resizeTo, autoStart, sharedTicker, canvas, useBackBuffer, powerPreference, eventFeatures, accessibilityOptions, gcActive, bezierSmoothness, webgl/webgpu/canvasOptions per-renderer overrides), app.stage/renderer/canvas/screen/domContainerRoot access, ResizePlugin, TickerPlugin, CullerPlugin (cullable, cullArea), custom ApplicationPlugin via ExtensionType.Application, start/stop lifecycle, and app.destroy() with releaseGlobalResources. Triggers on (in PixiJS code): PixiJS Application, app.init, app.stage, app.renderer, app.canvas, app.screen, app.domContainerRoot, ApplicationOptions, ApplicationPlugin, ExtensionType.Application, resizeTo, sharedTicker, skipExtensionImports, preferWebGLVersion, preserveDrawingBuffer, cullable, CullerPlugin, app.start, app.stop, app.destroy, releaseGlobalResources.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- pixijs-application
- license
- MIT
- description
- Use this skill when creating and configuring a PixiJS v8 Application. Covers new Application() + async app.init() options (width, height, background, antialias, resolution, autoDensity, preference, resizeTo, autoStart, sharedTicker, canvas, useBackBuffer, powerPreference, eventFeatures, accessibilityOptions, gcActive, bezierSmoothness, webgl/webgpu/canvasOptions per-renderer overrides), app.stage/renderer/canvas/screen/domContainerRoot access, ResizePlugin, TickerPlugin, CullerPlugin (cullable, cullArea), custom ApplicationPlugin via ExtensionType.Application, start/stop lifecycle, and app.destroy() with releaseGlobalResources. Triggers on (in PixiJS code): PixiJS Application, app.init, app.stage, app.renderer, app.canvas, app.screen, app.domContainerRoot, ApplicationOptions, ApplicationPlugin, ExtensionType.Application, resizeTo, sharedTicker, skipExtensionImports, preferWebGLVersion, preserveDrawingBuffer, cullable, CullerPlugin, app.start, app.stop, app.destroy, releaseGlobalResources.
02 资源文件 2
- 许可证LICENSE1.0 KB
- 参考文档references/application-options.md12.9 KB
03 SKILL.md 正文
Application: convenience wrapper owning renderer, root stage Container, canvas, Ticker/Resize plugins. All configuration goes to async app.init(), which creates renderer via autoDetectRenderer.
Quick Start
import { Application } from "pixi.js";
const app = new Application();
await app.init({
resizeTo: window,
background: "#1099bb",
antialias: true,
preference: "webgl",
autoDensity: true,
resolution: window.devicePixelRatio,
});
document.body.appendChild(app.canvas);
Related skills: pixijs-core-concepts (renderers, render pipeline), pixijs-ticker (render loop detail), pixijs-scene-container (working with app.stage). Non-browser setups (Web Worker, SSR, strict CSP) summarized in pixijs-core-concepts (Decision guide).
Core Patterns
Lifecycle: construct, init, render, destroy
import { Application } from "pixi.js";
const app = new Application();
await app.init({ width: 800, height: 600 });
document.body.appendChild(app.canvas);
// ... run scene, ticker drives app.render() automatically ...
app.destroy(
{ removeView: true, releaseGlobalResources: true },
{ children: true, texture: true, textureSource: true },
);
new Application()allocates instance but creates nothing.app.init(options)is async. Builds renderer, wires plugins.- TickerPlugin calls
app.render()every frame once init resolves (unlessautoStart: false). app.destroy(rendererDestroyOptions, stageDestroyOptions)— first argument forwards torenderer.destroy(). Passtrueor{ removeView: true }to remove canvas from DOM. AddreleaseGlobalResources: trueto drain global pools (batches, texture caches) when re-creating app in same tab. Omitting it usually causes flickering and stale textures after re-init (seepixijs-performance).
Key init options
await app.init({
width: 800,
height: 600,
background: 0x1099bb,
backgroundAlpha: 1,
antialias: true,
resolution: window.devicePixelRatio,
autoDensity: true,
preference: "webgpu",
autoStart: true,
sharedTicker: false,
resizeTo: window,
canvas: document.querySelector("#game-canvas") as HTMLCanvasElement,
});
Full option list in references/application-options.md: view/canvas, background, renderer preference (including array form), ticker, resize, culler, events, accessibility, WebGL/WebGPU context flags, Graphics bezier smoothness, GC, and per-renderer overrides (webgl / webgpu / canvasOptions).
Application properties
app.stage; // root Container; add all display objects here
app.renderer; // the WebGL/WebGPU/Canvas renderer instance
app.canvas; // the HTMLCanvasElement (insert it into the DOM yourself)
app.screen; // Rectangle describing the visible area in CSS pixels
app.domContainerRoot; // HTMLDivElement that holds DOMContainer overlays
app.stage is plain Container. Scene graph detail (transforms, addChild, destroy): see pixijs-scene-container. Renderer-level operations (extract, generateTexture, custom systems): see pixijs-core-concepts. Custom render pipes not covered by these skills; see RenderPipe API. Append app.domContainerRoot next to app.canvas to pin DOM elements to scene nodes (see DOMContainer API; requires import 'pixi.js/dom').
ResizePlugin
Set resizeTo at init (or reassign app.resizeTo later). Plugin then listens for resize event and calls renderer.resize() with target element's client size. Combine with autoDensity: true and resolution: window.devicePixelRatio for high-DPI output.
await app.init({ resizeTo: window });
app.resizeTo = document.querySelector("#game-container") as HTMLElement;
app.resize(); // immediate resize to the target's current size
app.queueResize(); // defer the resize to the next animation frame
app.cancelResize(); // drop a pending queueResize
Plugin keeps canvas matched to target; app.screen and app.canvas.width/height update in response. Read them after resize to place UI.
app.queueResize()— coalesces rapid calls by deferring to next frame.window.resizelistener uses it internally to skip redundant work.app.cancelResize()— cancels queued resize. Call before tearing down own layout code that triggeredqueueResize.
Ticker basics
TickerPlugin creates app.ticker and registers app.render() on it at UPDATE_PRIORITY.LOW. Control loop with app.start()/app.stop(). Add callbacks with app.ticker.add / app.ticker.addOnce:
app.ticker.add((ticker) => {
sprite.rotation += 0.01 * ticker.deltaTime;
});
app.ticker.addOnce(() => {
console.log("runs once on the next frame, then removes itself");
});
app.stop(); // pause the render loop (e.g. tab hidden)
app.start(); // resume
Callback receives Ticker instance. Read ticker.deltaTime for frame-rate-independent multiplier (~1.0 at 60fps), ticker.deltaMS for real milliseconds, ticker.FPS for current frame rate. See pixijs-ticker for priorities, FPS capping, onRender, shared vs private tickers, and v8 callback signature change.
Manual render loop
await app.init({ autoStart: false, width: 800, height: 600 });
document.body.appendChild(app.canvas);
function frame() {
updateScene();
app.render();
requestAnimationFrame(frame);
}
frame();
autoStart: false keeps TickerPlugin from auto-starting ticker. Call app.render() yourself (or app.renderer.render({ container: app.stage }), same effect). For registered ticker callbacks to fire, call app.ticker.update() in loop. TickerPlugin's registered callback already renders stage, so then omit separate app.render() call.
CullerPlugin (opt-in)
CullerPlugin skips rendering containers outside app.renderer.screen. Not registered by default. Add it before creating app:
import {
Application,
Container,
Sprite,
extensions,
CullerPlugin,
Rectangle,
} from "pixi.js";
extensions.add(CullerPlugin);
const app = new Application();
await app.init({ width: 800, height: 600 });
const world = new Container();
world.cullable = true; // this container is culled when its bounds leave the screen
world.cullableChildren = true; // default; set `false` to skip recursing into children
const tile = Sprite.from("tile.png");
tile.cullable = true;
world.addChild(tile);
app.stage.addChild(world);
Containers not culled unless cullable set. Override default bounds check with container.cullArea = new Rectangle(x, y, w, h) when child bounds are expensive to compute. Plugin wraps app.render() so Culler.shared.cull(app.stage, app.renderer.screen) runs before every frame. See pixijs-performance for when culling pays off.
Custom Application plugins
Extend Application by registering class with static init, static destroy, and static extension = ExtensionType.Application. Both run with this bound to Application instance, so this.renderer and this.stage are available.
import {
Application,
ExtensionType,
extensions,
type ApplicationOptions,
} from "pixi.js";
class FpsOverlay {
public static extension = ExtensionType.Application;
public static init(this: Application, options: Partial<ApplicationOptions>) {
// runs inside app.init() after the renderer is created
// attach props/methods to `this` to expose them on the app
}
public static destroy(this: Application) {
// runs inside app.destroy() — tear down anything you attached
}
}
extensions.add(FpsOverlay);
Plugins initialize in registration order, destroy in reverse. For typed plugin options, extend PixiMixins.ApplicationOptions:
declare global {
namespace PixiMixins {
interface ApplicationOptions {
fpsOverlay?: { visible?: boolean };
}
}
}
await app.init({ fpsOverlay: { visible: true } });
Built-in ResizePlugin, TickerPlugin, and opt-in CullerPlugin use same contract. With skipExtensionImports: true, register needed built-ins yourself (extensions.add(ResizePlugin, TickerPlugin)).
Common Mistakes
[CRITICAL] Passing options to the constructor
Wrong:
const app = new Application({ width: 800, height: 600 });
document.body.appendChild(app.canvas);
Correct:
const app = new Application();
await app.init({ width: 800, height: 600 });
document.body.appendChild(app.canvas);
In v8 Application constructor takes no arguments. Options passed there are ignored and log deprecation warning. Renderer is only created inside async init() call.
[HIGH] Using app.view instead of app.canvas
Wrong:
document.body.appendChild(app.view);
Correct:
document.body.appendChild(app.canvas);
app.view renamed to app.canvas in v8. Old getter still works but emits deprecation warning.
[MEDIUM] Touching app.canvas or app.renderer before init resolves
Wrong:
const app = new Application();
document.body.appendChild(app.canvas);
app.init({ width: 800, height: 600 });
Correct:
const app = new Application();
await app.init({ width: 800, height: 600 });
document.body.appendChild(app.canvas);
app.renderer, app.canvas, and app.screen only usable once init() promise resolves. Before that, app.renderer is undefined. app.canvas / app.screen getters throw TypeError because they read from missing renderer.
API Reference
04 同仓库更多 Skills
wiki-builder
Create and maintain a local Markdown research wiki (sources with provenance, compiled concept/source pages, index, maintenance log) driven by a per-wiki config. Use when the user wants to start a wiki or knowledge base, ingest sources into one, or query and update it; use wiki-page-writer for a single code deep-dive page.
refactoring-guru
Diagnose a named code smell and apply the smallest behavior-preserving refactoring, with verification before and after and an explicit stop condition. Use for structural refactors (extract, move, consolidate, change ownership), not for feature or bug work; for readability cleanup of recent changes use code-simplification.
legacy-seams
When changing untested legacy code, pin the observed results with characterization tests and open the smallest seam that substitutes only the blocking dependency, separate from any later logic change. Use when a clock, random source, I/O, global, or hidden constructor blocks a test or a safe edit. Use test-driven-development for a new behavior or a bug, refactoring-guru for one named structural refactor after the seam exists, and code-refactoring-tech-debt to choose which legacy to replace.
idea-refine
Refine a raw idea into a one-page brief (problem statement, recommended direction, assumptions to validate, MVP scope, not-doing list) through divergent then convergent thinking. Use when an idea is still vague or you want options and a stress test before committing; use interview-me when the goal itself is unclear and spec-driven-development once the direction is chosen.
code-review-and-quality
Review rubric and approval standard for any change before merge, including code written by you, another agent, or a human: five axes (correctness, readability, architecture, security, performance), change sizing, structural remedies, severity labels, and feedback technique. Use to judge whether a change is fit to merge; use code-review to run a PR or diff review end to end.
code-perfection
Smell and style gate for code you write or change. Bans known code smells (long method, large class, primitive obsession, long parameter list, data clumps, duplicate code, dead code, feature envy, shotgun surgery, flag arguments, message chains) and enforces behavior-preserving structure. On Scala files, enforces worxbend style. Use while implementing, reviewing a diff for smells, or when a smell or style violation is suspected. Routine construction stays with code-complete. SOLID and DRY stay with clean-code-guard. One named structural refactor stays with refactoring-guru.