TextureManager
1.2.0+
Manage textures.
Creation
Creating a texture is done using load:
const texture = await engine.textures.load('my-image.png');
Alternatively, textures can be created directly via a loaded image using create.
Static Members
- .constructor(engine) ⇒ TextureManager
- TextureManager.fetchImage(src, crossOrigin) ⇒ Promise<HTMLImageElement>
- TextureManager.fetchImageBitmap(src, options) ⇒ Promise<ImageBitmap>
Methods
Constructor
.constructor(engine: WonderlandEngine) ⇒ TextureManager
| Param | Type | Description |
|---|---|---|
engine | WonderlandEngine |
Static Members
TextureManager.fetchImage(src: string | Blob, crossOrigin: string) ⇒ Promise<HTMLImageElement>
| Param | Type | Description |
|---|---|---|
src | string | Blob | |
crossOrigin | string |
TextureManager.fetchImageBitmap(src: string | Blob, options: Partial<ImageBitmapOptions>) ⇒ Promise<ImageBitmap>
| Param | Type | Description |
|---|---|---|
src | string | Blob | |
options | Partial<ImageBitmapOptions> |
Methods
.create(image: ImageLike, params: TextureParameters) ⇒ Texture
Create a new texture from an image or video.
Usage
const img = new Image();
img.load = function(img) {
const texture = engine.textures.create(img);
};
img.src = 'my-image.png';
Note: The media must already be loaded. To automatically load the media and create a texture, use load instead.
| Param | Type | Description |
|---|---|---|
image | ImageLike | Media element to create the texture from. @ret\urns The new texture with the media content. |
params | TextureParameters |
.load(filename: string, crossOrigin: string) ⇒ Promise<Texture>
Load an image from URL as Texture.
Usage
const texture = await engine.textures.load('my-image.png');
Returns: Loaded texture.
| Param | Type | Description |
|---|---|---|
filename | string | URL to load from. |
crossOrigin | string | Cross origin flag for the image object. |