Application
Just like PIXI.Application, it sets up the Renderer, Ticker and root Container. If you wish, you can manually render those components instead.
PIXI.Application description from PixiJS
sourceConvenience class to create a new PixiJS application.
This class automatically creates the renderer, ticker and root container.
Usage
<script> import { Application, Text } from 'svelte-pixi'</script>
<Application width={400} height={400} antialias> <Text x={200} y={200} anchor={0.5} text="Hello World" style={{ fill: 'white' }} /></Application><script> import { Application, Text } from 'svelte-pixi/svelte-4'</script>
<Application width={400} height={400} antialias> <Text x={200} y={200} anchor={0.5} text="Hello World" style={{ fill: 'white' }} /></Application>Custom View
If you want to customize the element that the canvas is rendered into, you can use the view slot. The canvas will be appended as a child of the slot element.
<script> import { Application, Text } from 'svelte-pixi'</script>
<Application width={400} height={400} antialias autoDensity> {#snippet view()} <div class="custom"> <!-- canvas will be placed here --> </div> {/snippet}
<!-- pixi components go here --> <Text x={200} y={200} anchor={0.5} text="Hello World" style={{ fill: 'white' }} /></Application>
<style> .custom :global(canvas) { border: 5px solid tomato; border-radius: 5px; }</style><script> import { Application, Text } from 'svelte-pixi/svelte-4'</script>
<Application width={400} height={400} antialias autoDensity> <div slot="view" class="custom"> <!-- canvas will be placed here --> </div>
<!-- pixi components go here --> <Text x={200} y={200} anchor={0.5} text="Hello World" style={{ fill: 'white' }} /></Application>
<style> .custom :global(canvas) { border: 5px solid tomato; border-radius: 5px; }</style>Custom Stage
PIXI.Application automatically creates a root container at app.stage. If you want to customize it you can either modify it directly
or use the stage snippet to manually render it as a Container component.
<script> import { Application, Text, Container} from 'svelte-pixi'
let mouse = { x: 0, y: 0 }</script>
<Application width={400} height={400} antialias autoDensity> <!-- customize the app.stage instance --> {#snippet stage({ app, children })} <Container instance={app.stage} hitArea={app.screen} eventMode="static" onpointermove={(e) => mouse = e.data.global} > <!-- your pixi components go here --> <Text x={200} y={200} anchor={0.5} text={`Mouse: ${Math.round(mouse.x)}, ${Math.round(mouse.y)}`} style={{ fill: 'white' }} />
<!-- alternatively, you can do {@render children()} here and put your components outside of this snippet. they will both work the same way. --> </Container> {/snippet}</Application><script> import { Application, Text, Container } from 'svelte-pixi/svelte-4' let mouse = { x: 0, y: 0 }</script>
<Application width={400} height={400} antialias autoDensity> <!-- customize the app.stage instance --> <slot slot="stage" let:app> <Container instance={app.stage} hitArea={app.screen} eventMode="static" on:pointermove={(e) => mouse = e.detail.data.global} > <!-- your pixi components go here --> <Text x={200} y={200} anchor={0.5} text={`Mouse: ${Math.round(mouse.x)}, ${Math.round(mouse.y)}`} style={{ fill: 'white' }} /> </Container> </slot></Application>
<style> .custom :global(canvas) { border: 5px solid tomato; border-radius: 5px; }</style>Render on Demand
<script> import { onMount } from 'svelte' import { Text, Application } from 'svelte-pixi' import DraggableCircle from '$lib/components/DraggableCircle.svelte'</script>
<Application width={400} height={400} antialias render="demand" onrender={() => console.log('render')}> <DraggableCircle x={200} y={200} /> <Text x={200} y={300} text="Click and drag" style={{ fill: 'white' }} anchor={0.5} /></Application><script> import { onMount } from 'svelte' import { Text, Application } from 'svelte-pixi/svelte-4' import DraggableCircle from '$lib/components/DraggableCircle.svelte'</script>
<Application width={400} height={400} antialias render="demand" on:render={() => console.log('render')}> <DraggableCircle x={200} y={200} /> <Text x={200} y={300} text="Click and drag" style={{ fill: 'white' }} anchor={0.5} /></Application>API
Props
* denotes required
| Name | Description |
|---|---|
antialias | booleanWhether to enable anti-aliasing. This may affect performance. |
autoDensity | booleanResizes renderer view in CSS pixels to allow for resolutions other than 1. |
autoInit | booleanIf true, Application.init() is called immediately. If you want to initialize it yourself with a custom instance, set this to false. |
autoStart | booleanAutomatically starts the rendering after the construction.
Note: Setting this parameter to |
background | stringnumbernumber[]Float32ArrayUint8ArrayUint8ClampedArrayPIXI.HslColorPIXI.HslaColorPIXI.HsvColorPIXI.HsvaColorPIXI.RgbColorPIXI.RgbaColorPIXI.ColorAlias for backgroundColor |
backgroundAlpha | numberTransparency of the background color, value from |
backgroundColor | stringnumbernumber[]Float32ArrayUint8ArrayUint8ClampedArrayPIXI.HslColorPIXI.HslaColorPIXI.HsvColorPIXI.HsvaColorPIXI.RgbColorPIXI.RgbaColorPIXI.ColorThe background color used to clear the canvas. See {@link ColorSource} for accepted color values. |
bezierSmoothness | numberA value from 0 to 1 that controls the smoothness of bezier curves (the higher the smoother) |
canvas | PIXI.ICanvasThe canvas to use as a view, optional. |
clearBeforeRender | booleanWhether to clear the canvas before new render passes. |
context | nullWebGL2RenderingContextUser-provided WebGL rendering context object. |
depth | booleanWhether to ensure the main view has can make use of the depth buffer. Always true for WebGL renderer. |
eventFeatures | Partial<PIXI.EventSystemFeatures>The event features that are enabled by the EventSystem. |
eventMode | "auto""none""passive""static""dynamic"The default event mode for all display objects. |
failIfMajorPerformanceCaveat | boolean |
forceFallbackAdapter | booleanForce the use of the fallback adapter |
height | numberThe height of the screen. |
hello | booleanWhether to log the version and type information of renderer to console. |
instance | TThe PIXI.Application instance. This can be manually set or bound to. Note: if manually set any PIXI.ApplicationOptions props will not be set as they are passed into the constructor |
manageImports | boolean |
multiView | booleanWhether to enable multi-view rendering. Set to true when rendering to multiple canvases on the dom. |
oninit | (ev: { application: T; }) => voidCalled when PIXI.Application.init() method resolves |
onpostrender | (item: unknown) => voidEvent handler for the postrender PIXI.Runner |
onprerender | (item: unknown) => voidEvent handler for the prerender PIXI.Runner |
onrender | (item: unknown) => voidEvent handler for the render PIXI.Runner |
onrenderstart | (item: unknown) => voidEvent handler for the renderStart PIXI.Runner |
powerPreference | "low-power""high-performance"An optional hint indicating what configuration of GPU is suitable for the WebGL context,
can be |
preference | "webgpu""webgl"The preferred renderer type. WebGPU is recommended as its generally faster than WebGL. |
preferWebGLVersion | 12The preferred WebGL version to use. |
premultipliedAlpha | booleanWhether the compositor will assume the drawing buffer contains colors with premultiplied alpha. |
preserveDrawingBuffer | booleanWhether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve
its value until cleared or overwritten. Enable this if you need to call |
render | "auto""demand" |
renderableGCActive | booleanIf set to true, this will enable the garbage collector on the GPU. |
renderableGCFrequency | numberFrames between two garbage collections. |
renderableGCMaxUnusedTime | numberThe maximum idle frames before a texture is destroyed by garbage collection. |
resizeTo | HTMLElementWindowElement to automatically resize the renderer to. |
resolution | numberThe resolution / device pixel ratio of the renderer. |
roundPixels | boolean |
sharedTicker | booleanSet |
skipExtensionImports | booleanWhether to stop PixiJS from dynamically importing default extensions for the renderer. It is false by default, and means PixiJS will load all the default extensions, based on the environment e.g browser/webworker. If you set this to true, then you will need to manually import the systems and extensions you need. e.g.
|
textureGCActive | booleanIf set to true, this will enable the garbage collector on the GPU. |
textureGCAMaxIdle | number |
textureGCCheckCountMax | numberFrames between two garbage collections. |
textureGCMaxIdle | numberThe maximum idle frames before a texture is destroyed by garbage collection. |
useBackBuffer | booleanif true will use the back buffer where required |
webgl | Partial<PIXI.WebGLOptions>Optional WebGLOptions to pass only to the WebGL renderer |
webgpu | Partial<PIXI.WebGPUOptions>Optional WebGPUOptions to pass only to WebGPU renderer. |
width | numberThe width of the screen. |
Snippets
| Name | Type |
|---|---|
| children | Snippet<[]> |
| loading | Snippet<[]> |
| stage | Snippet<[{ app: T; children: Snippet<[]>; }]> |
| view | Snippet<[]> |
Props
| Name | Description |
|---|---|
antialias | Sets antialias |
autoDensity | Resizes renderer view in CSS pixels to allow for resolutions other than 1. |
autoInit true | booleanCalls init() on the Application immediately |
autoStart | Automatically starts the rendering |
background | PIXI.ColorSourceAlias for backgroundColor |
backgroundAlpha | numberValue from 0 (fully transparent) to 1 (fully opaque). |
backgroundColor | PIXI.ColorSourceThe background color of the rendered area (shown if not transparent). |
bezierSmoothness | numberA value from 0 to 1 that controls the smoothness of bezier curves (the higher the smoother) |
clearBeforeRender | booleanThis sets if the renderer will clear the canvas or not before the new render pass. |
context | WebGL2RenderingContextUser-provided WebGL rendering context object. |
depth | booleanWhether to ensure the main view has can make use of the depth buffer. Always true for WebGL renderer. |
eventFeatures | PIXI.EventSystemOptions['eventFeatures']The event features that are enabled by the EventSystem. |
eventMode | PIXI.EventModeThe default event mode mode for all display objects. |
failIfMajorPerformanceCaveat | boolean |
forceFallbackAdapter | booleanForce the use of the fallback adapter |
height | The height of the renderers view. |
hello | booleanWhether to log the version and type information of renderer to console. |
instance | PIXI.ApplicationThe PIXI.Application instance. This can be manually set or bound to. Note: if manually set, props will not be applied. |
multiView | booleanWhether to enable multi-view rendering. Set to true when rendering to multiple canvases on the dom. |
powerPreference | WebGLPowerPreferenceParameter passed to webgl context, set to "high-performance" for devices with dual graphics card. (WebGL only). |
preference | 'webgl''webgpu'The preferred renderer type. WebGPU is recommended as its generally faster than WebGL. |
preferWebGLVersion | 12The preferred WebGL version to use. |
premultipliedAlpha | booleanWebGL Only. Whether the compositor will assume the drawing buffer contains colors with premultiplied alpha. |
preserveDrawingBuffer | Enables drawing buffer preservation, enable this if you need to call toDataUrl on the WebGL context. |
render 'auto' | 'auto''demand'falseChanges the rendering method auto - render on each tick at the target FPS demand - render only when components have been updated |
renderableGCActive | booleanIf set to true, this will enable the garbage collector on the GPU. |
renderableGCFrequency | numberFrames between two garbage collections. |
renderableGCMaxUnusedTime | The maximum idle frames before a texture is destroyed by garbage collection. @default 60 |
resizeTo | WindowHTMLElementElement to automatically resize stage to. |
resolution | numberThe resolution / device pixel ratio of the renderer. |
roundPixels | |
skipExtensionImports | booleanWhether to stop PixiJS from dynamically importing default extensions for the renderer. It is false by default, and means PixiJS will load all the default extensions, based on the environment e.g browser/webworker. If you set this to true, then you will need to manually import the systems and extensions you need. |
textureGCActive | booleanIf set to true, this will enable the garbage collector on the GPU. |
textureGCCheckCountMax | numberFrames between two garbage collections. |
textureGCMaxIdle | numberThe maximum idle frames before a texture is destroyed by garbage collection. |
useBackBuffer | booleanif true will use the back buffer where required |
webgl | PIXI.WebGLRendererOptionsOptional WebGLOptions to pass only to the WebGL renderer |
webgpu | PIXI.WebGPUOptionsOptional WebGPUOptions to pass only to WebGPU renderer. |
width | The width of the renderers view. |
Slots
| Name | Props | Fallback |
|---|---|---|
| default | {} | |
| loading | {} | |
| stage | { app: any } | <Container instance={instance.stage}>
<slot />
</Container> |
| view | { slot: view } | <div></div> |
Events
| Name | Type | Detail |
|---|---|---|
| init | dispatched | |
| postrender | forwarded | |
| prerender | forwarded | |
| render | forwarded | |
| renderStart | forwarded |