Skip to main content

<pc-asset>

The <pc-asset> tag is used to define an asset.

Usage
  • It must be a direct child of <pc-app>.

Attributes

AttributeTypeDefaultDescription
atlasString-For sprite assets: the id of the textureatlas <pc-asset> this sprite reads from. The atlas must be declared before the sprite
dataString-Inline JSON asset data. Used by texture atlases (frame definitions) and sprites
frame-keysString-For sprite assets: space- or comma-separated list of atlas frame keys that make up the sprite
idString-Unique identifier used by other tags to reference this asset
lazyFlag-Whether to defer loading until first referenced or explicitly requested
pixels-per-unitNumber"1"For sprite assets: number of pixels per world unit
render-modeEnum"simple"For sprite assets: "simple" | "sliced" | "tiled". Use "sliced" for 9-slice panels
srcString-Path to the asset file
typeEnuminferredAsset type: "audio" | "binary" | "css" | "container" | "font" | "gsplat" | "html" | "json" | "script" | "shader" | "sprite" | "text" | "texture" | "textureatlas"

Example

<pc-app>
<!-- Script asset -->
<pc-asset src="assets/scripts/animate.mjs"></pc-asset>
<!-- GLB asset -->
<pc-asset src="assets/models/car.glb" id="car"></pc-asset>
</pc-app>

Sprites are defined by a texture atlas (which holds the frame definitions) and one or more sprite assets that reference it. The atlas must be declared before any sprite that uses it:

<pc-app>
<!-- Texture atlas, with inline frame definitions -->
<pc-asset id="ui-sheet" type="textureatlas" src="assets/textures/ui.png"
data='{"frames":{"3":{"name":"panel","border":[10,10,10,10],"rect":[41,1,100,100],"pivot":[0.5,0.5]}}}'></pc-asset>
<!-- 9-sliced sprite that reads frame "3" from the atlas -->
<pc-asset id="panel" type="sprite" atlas="ui-sheet" frame-keys="3" render-mode="sliced"></pc-asset>
</pc-app>

JavaScript Interface

You can programmatically create and manipulate <pc-asset> elements using the AssetElement API.