Pixi’VN
indexFunctions

Function: addImage()

pixi-vn on GitHub

Call Signature

> addImage(alias, options?): ImageSprite

Defined in: src/canvas/functions/image-utility.ts:21

Add a image in the canvas, using alias as the image alias. The image is not shown: use ImageSprite.load.

Parameters

alias

string

The unique alias of the component, also used as the alias of the asset (it must be registered in the asset cache or manifest).

options?

ImageSpriteOptions

The options of the image.

Returns

ImageSprite

This function returns an ImageSprite that you can use to manipulate the component.

Throws

when alias is not registered in the asset cache.

Example

Assets.add({ alias: "bunny", src: "https://pixijs.com/assets/bunny.png" });
const bunny = addImage("bunny", { xAlign: 0.5 });
await bunny.load();

Call Signature

> addImage(alias, imageUrl?, options?): ImageSprite

Defined in: src/canvas/functions/image-utility.ts:43

Add a image in the canvas. Is the same that showImage, but the image is not shown. If you want to show the image, then you need to use the function ImageSprite.load.

Parameters

alias

string

is the unique alias of the image. You can use this alias to refer to this image

imageUrl?

string

The url of the image. If you have initialized the "asset matrix", you can use the alias of the texture. If you don't provide the URL, then the alias is used as the URL.

options?

ImageSpriteOptions

The options of the image.

Returns

ImageSprite

This function returns an ImageSprite that you can use to manipulate the component.

Throws

when imageUrl is not provided and alias is not registered in the asset cache.

Example

Assets.add({ alias: "bunny", src: "https://pixijs.com/assets/bunny.png" });

// "bunny" is the alias of the component and of the asset
const bunny1 = addImage("bunny");
await bunny1.load();
// a different alias for the component: (alias, assetAlias, options)
const bunny2 = addImage("bunny2", "bunny", { xAlign: 1 });
await bunny2.load();

On this page