Documentation Index
Fetch the complete documentation index at: https://mintlify.com/hetari/creative-coding/llms.txt
Use this file to discover all available pages before exploring further.
usePixiApp manages the complete lifecycle of a PixiJS v8 Application instance inside a Vue component. It handles the dynamic import of PixiJS (keeping the library out of your initial bundle), creates and initialises the Application, appends its canvas to a container element you supply, and tears everything down safely on component unmount — using tryOnUnmounted from VueUse for SSR safety. You never need to call app.destroy() yourself.
Signature
Parameters
A Vue
TemplateRef or ShallowRef pointing to the container HTMLElement. When mountApp runs, the PixiJS canvas (instance.canvas) is appended as a child of this element. If the ref is null at call time, mountApp returns early without throwing.Return Value
A shallow reactive reference to the live PixiJS
Application instance. The value is null before mountApp has been called and after the component unmounts. Use app.value.stage and app.value.renderer to build your scene.Dynamically imports PixiJS, constructs a new
Application, calls instance.init(options), and appends instance.canvas to containerRef. If a previous Application instance already exists (e.g. after HMR), it is destroyed first before the new one is created.Responsibilities
The composable owns the following concerns so you do not have to repeat them across sketches:Owned by usePixiApp | Owned by the caller (your sketch) |
|---|---|
Dynamic import of pixi.js | Loading image and texture assets |
Application creation and init() | Creating sprites, filters, and uniforms |
Appending canvas to the container | Setting up interaction and animation loops |
| Destroying the instance on unmount | Responding to window resize events |
Usage Example
The following is taken from theswiper sketch, which uses usePixiApp to build a full-screen PixiJS shader transition:
Hot Reload
CallingmountApp() again when app.value is already set will destroy the previous instance — app.destroy(true, { children: true }) — before creating a new one. This makes it safe to call on HMR re-mount without leaking WebGL contexts or canvas elements.
Teardown
On component unmount,usePixiApp calls tryOnUnmounted (VueUse) to destroy the Application with { children: true }, which recursively destroys all textures and display objects attached to the stage. The tryOnUnmounted variant is used instead of the plain onUnmounted to remain safe in SSR environments where lifecycle hooks may not fire.