track

Returns a writable store that gets updated during a low-priority tick. If there’s no Ticker, it will run during the PIXI.Renderer’s postrender event.

This is useful for watching a property on a PixiJS instance that is getting updated outside of the component (e.g. a physics system). It can also be used to bind props, as Svelte Pixi components don’t support bind: syntax for instance properties.

<script>
  import { Container, track } from 'svelte-pixi'

  let instance
  let x = track(() => instance.x, 100)
  let y = track(() => instance.y, 100)

  $: if ($x > 200) {
    console.log('x is greater than 200!')
  }
</script>

<Container bind:instance x={$x} y={$y} />

Type Definition

function track<T>(getter: () => T, initial?: T): Writable<T>