Skip to content

Assets

Preloads the assets (textures, audio, etc.) used by your components using the PixiJS Assets API. It contains three slots: default, fallback, and error. The default slot will not render until the assets have finished loading.

You can show progress by using the progress prop from the fallback slot.

Default Slot

You can also access the loaded entry through the default slot, which is an object that you can iterate over.

Alias

You can specify aliases for resources using the alias and entry props, or by passing an array of UnresolvedAsset objects:

vue
<template>
  <assets
    :entry="[
      { alias: 'flowerTop', src: '/assets/flowerTop.png' },
      { alias: 'eggHead', src: '/assets/eggHead.png' },
    ]"
  >
    <sprite texture="flowerTop" />
    <sprite texture="eggHead" />
  </assets>
</template>

You can also use the alias and entry props together for a single asset:

vue
<template>
  <assets alias="mySprite" entry="/assets/mySprite.png" @loaded="onLoaded">
    <sprite texture="mySprite" />
  </assets>
</template>

Bundles

Use <assets-bundle> to load asset bundles, either from a manifest or by defining bundles inline:

vue
<template>
  <!-- Load from manifest -->
  <assets-bundle manifest="/assets/manifest.json" entry="game-screen">
    <template #fallback="{ progress }">
      <text :anchor="0.5" :x="120" :y="120">
        {{ `Loading ${progress}%` }}
      </text>
    </template>
    <template #default="{ data }">
      <sprite :texture="data.background" />
    </template>
  </assets-bundle>

  <!-- Define bundle inline -->
  <assets-bundle
    id="my-bundle"
    :entry="[
      { alias: 'bg', src: '/assets/bg.png' },
      { alias: 'hero', src: '/assets/hero.png' },
    ]"
  >
    <template #default="{ data }">
      <sprite :texture="data.bg" />
    </template>
  </assets-bundle>
</template>

API

Assets Props

NameTypeDefaultDescription
aliasstring arrayundefinedAlias name(s) for the asset being loaded.
entrystring array objectundefinedThe asset entry to load. Can be a URL, array of URLs, or asset descriptor object(s).
autoloadbooleantrueWhether to automatically load assets via Assets.load.
autounloadbooleanfalseWhether to unload assets when the component is unmounted.
backgroundbooleanfalseLoad assets in the background while the application is running.
basePathstringundefinedBase path prepended to all asset URLs.

Assets Events

NameTypeDescription
loadedfunctionEmitted when all assets have finished loading.
progressfunctionEmitted when loading progress updates.
errorfunctionEmitted when asset loading fails.

Assets Slots

NameTypeDescription
default({ data }): voidRendered after loading completes. data contains the loaded assets.
fallback({ progress }): voidRendered while assets are loading. progress is a number from 0 to 1.
error({ error }): voidRendered when asset loading fails.

AssetsBundle Props

NameTypeDefaultDescription
manifestobject stringundefinedAssets manifest containing bundle definitions.
entrystring array objectundefinedBundle name(s) to load, or inline bundle assets when used with id.
idstringundefinedBundle ID for inline bundle definitions.
autoloadbooleantrueWhether to automatically load the bundle.
autounloadbooleanfalseWhether to unload the bundle when the component is unmounted.
backgroundbooleanfalseLoad the bundle in the background.

AssetsBundle Events

NameTypeDescription
loadedfunctionEmitted when the bundle has finished loading.
progressfunctionEmitted when loading progress updates.