v8.0.0
Brings support for PixiJS v8.6.5 and Svelte 5 (Svelte 4 components still available). If you are upgrading from a previous version, please read the PixiJS v8 migration guide to get an overview of the changes in PixiJS. Most of these are handled for you by SveltePixi but there are still a few breaking changes.
Installation
npm install pixi.js@~8.6.0 svelte-pixi@~8.0.0Features
-
PixiJS v8.6 support
-
Rewritten for Svelte 5
- Svelte 4 components are still available from
svelte-pixi/svelte-4. Read more on migrating to Svelte 5
- Svelte 4 components are still available from
-
tick utility function
<script>import { tick } from 'svelte-pixi'let elapsed = tick((ticker, prev = 0) => prev + ticker.deltaTime)$effect(() => console.log($elapsed))</script>Note that this deprecates
track- see below -
PerspectiveMesh component
Bug fixes
- Fix event listeners triggering twice
- Fix svelte package.json exports field (#41)
instanceprops are now set to undefined when unmounted
Breaking Changes
Textures
In PixiJS v8 all textures must be loaded before use. You can use the AssetsLoader component to do this.
<script> import * as PIXI from 'pixi.js' import { AssetsLoader, Sprite } from 'svelte-pixi'</script>
<AssetsLoader assets={['/my-texture.png']}> <Sprite texture={PIXI.Texture.from('/my-texture.png')} /></AssetsLoader>Reducing bundle size
The method for reducing bundle size has changed. PixiJS v8 now ships a single bundle and dynamically imports extras during Application initialization. If you were using a custom pixi.js bundle in v7 or earlier, see the new guide on reducing bundle size.
Components
Application / Renderer
Initialization is now async
In Pixi v8 Application and Renderer are now initialiazed asynchronously. The Application and Renderer components are affected in the following ways:
-
When
<Application />mounts it will callinit()on the application instance. When it resolves the children are rendered.- This should be very quick but if you want to render HTML while it initializes you can use the
loadingsnippet/slot. - The
instanceprop will be bound immediately to the Application but it will not containrendereretc. properties until the initialization is complete. You can use theoninitprop (oron:initin Svelte 4) to know when it is ready.
- This should be very quick but if you want to render HTML while it initializes you can use the
-
When
<Renderer />mounts will callautoDetectRenderer()to get the renderer if theinstanceprop is not provided.- Like Application, a
loadingsnippet/slot will be rendered while it awaits and it will emit anoninit/on:initevent when it is ready. - Unlike Application the
instanceprop will not be bound until it finishes. - If the
instanceprop is provided it will render immediately.
- Like Application, a
You most likely aren’t affected by this unless you are manually binding to the instance props.
See the Application and Renderer documentation for more information.
Changes to default prop values
In previous versions of SveltePixi the default Application/Renderer props were set to match PixiJS defaults according to their documentation. This was not ideal as it did not stay in sync with future PixiJS versions when those defaults changed.
Now, all props that are used for the PIXI.Application/Renderer options have no defaults so that PixiJS determines the default behaviour.
If you need to maintain the previous behaviour, set the Application or Renderer props to the following:
<Application autoDensity antialias resolution={1} backgroundAlpha={1} backgroundColor={0x000000} height={600} width={800} preserveDrawingBuffer={false}/>Removed props
As a result of PixiJS API changes, the following props have been removed:
useContextAlpha- use
premultipliedAlphaandbackgroundAlphainstead.
- use
forceCanvasstage(Renderer only)- use a Container as a child instead and bind to its instance
BitmapText
Props
fontNameis nowfontFamilymaxWidthis nowwordWrapWidthtintis nowfill
Container
Props
namedeprecated, uselabelinstead. name will set label on instance.isMaskremovedisSpriteremovedcacheAsBitmapMultisampleremovedcacheAsBitmapResolutionremovedcacheAsBitmapdeprecated by PixiJS v8, usecacheAsTextureinsteadtransformremoved in PixiJS for groupTransform, localTransform, and worldTransform properties, but they’re all read-only anyway
Graphics
If using the Svelte 4 components, there has been a slight change in the reactivity of functions when used with Svelte 5.
Previously you could inline a function to the draw prop and it would update when any used reactive state changed, but now the function must be declared as a reactive variable.
<script> import { Graphics } from 'svelte-pixi'
let foo = 0
$: draw = (g) => { console.log(foo) }</script>
<Graphics {draw} />
<!-- this will no longer be reactive --><Graphics draw={(g) => { console.log(foo) }}/>Mesh
Props
drawModeremoved
NineSlicePlane -> NineSliceSprite
Renamed in PixiJS to NineSliceSprite
Props
geometryremovedstateremoveddrawModeremoved
ParticleContainer
Received an overhaul in PixiJS v8. Recommend reading the ParticleContainer documentation for how to use it with the new APIs.
Props
maxSizeremovedbatchSizeremovedautoResizeremovedpropertiesremoved
SimplePlane -> MeshPlane
Renamed in PixiJS to MeshPlane
Props
drawModeremovedgeometryremoved, useverticesXandverticesYinstead
SimpleRope -> MeshRope
Renamed in PixiJS to MeshRope
Props
drawModeremoved
TilingSprite
Props
uvMatrixremoved
Ticker
Props
Defaults for the following props have been removed and will now use the defaults that PixiJS designates:
- maxFPS
- minFPS
- speed
autoStart remains defaulted to true for convenience
onTick
The event payload for the ticker has changed in PixiJS v8. The payload is now the ticker instance.
<script> import { onTick } from 'svelte-pixi'
onTick((ticker) => { console.log(ticker.deltaTime) })</script><script> import { Ticker } from 'svelte-pixi'</script>
<Ticker ontick={(ticker) => console.log(ticker.deltaTime)} />Deprecations
track
track() has been depracted in favour of tick() and will be removed in a future version.
tick works similarly but has a few differences:
- receives the parent Ticker instance in the callback
- executes the callback immediately to get the initial value, rather than waiting for the next tick
- requires a parent Ticker in the component tree
In most cases the migration from track will look like this:
<script> import { track } from 'svelte-pixi' import { tick } from 'svelte-pixi' let instance
let x = track(() => instance.x, 100) let x = tick(() => instance?.x ?? 100)</script>
<Container bind:instance />This also makes it easier to derive values from the Ticker:
<script> import { onTick, tick } from 'svelte-pixi'
// using onTick let elapsed = 0 onTick((ticker) => { elapsed += ticker.deltaTime })
// using tick let elapsed = tick((ticker, prev = 0) => prev + ticker.deltaTime)</script>Known issues
Container.name warning
You may notice the following warning when using components from svelte-pixi/svelte-4:
PixiJS Deprecation Warning: Container.name property has been removed, use Container.label instead
The SveltePixi components do use label instead of name now, but there are some reactive statements that causes the Svelte compiler
to do a key comparison on the instance, triggering this warning when it reads instance.name.
This only happens with the Svelte 4 components and given that this is a warning and Svelte 4 components will be removed next version, this likely won’t get fixed.