UNPKG

duckengine

Version:
43 lines (41 loc) 1.13 kB
import { Duck } from '../..'; import TextureBase from './textureBase'; /** * @class Texture * @classdesc Creates a DuckEngine Texture * @description The Texture Class. Stores images and colors in a class * @template type Texture type, 'image' | 'color' | 'either' * @extends TextureBase * @since 2.0.0 */ export default class Texture< type extends Duck.Types.Texture.Type > extends TextureBase<type> { /** * @constructor Texture * @description Creates a texture * @param {Duck.Types.Texture.Type} type Texture type * @param {HTMLImageElement:string} texture Texture source * @param {number} w Width of texture * @param {number} h Height of texture * @since 2.0.0 */ constructor( type: Duck.Types.Texture.Type, texture: type extends 'image' ? HTMLImageElement : type extends 'either' ? string | HTMLImageElement : string, w: number, h: number ) { if (type === 'image') { super('image', 'base', texture as HTMLImageElement, w, h); } else if (type === 'color') { super('color', 'base', texture as string, w, h); } else { super('either', 'base', texture, w, h); } } }