LogoPixi’VN
indexFunctions

Function: addImage()

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

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

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

is the url of the image. If you don't provide the url, then the alias is used as the url.

options?

ImageSpriteOptions

The options of the image.

Returns

ImageSprite

the container of the image.

Throws

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

Example

let bunny1 = addImage("bunny1", "https://pixijs.com/assets/bunny1.png")
await bunny1.load()
Assets.add({ alias: "bunny2", src: "https://pixijs.com/assets/bunny2.png" })
let bunny2 = addImage("bunny2")
await bunny2.load()