UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

63 lines (62 loc) 1.8 kB
import Color from "../utils/color"; import Texture from "./texture"; export declare enum GradientType { LINEAR = 0, RADIAL = 1 } export declare enum GradientDirection { RIGHT_TO_LEFT = 0, LEFT_TO_RIGHT = 1, TOP_TO_BOTTOM = 2, BOTTOM_TO_TOP = 3, BR_TO_TL = 4, BL_TO_TR = 5 } /** * Represents a color stop on the canvas gradient. * * @field `offset` Where the stop is along the gradient (between 0 and 1). * @field `color` The color at the stop */ export interface ColorStop { offset: number; color: Color; } /** * Represents a texture with a gradient as it's image. */ export default class GradientTexture extends Texture { stops: ColorStop[]; resolution: number; type: GradientType; direction: GradientDirection; private static canvas; private static ctx; /** * Creates a {@link GradientTexture}. * * Before use the texture must be refreshed, this is done by calling the `refresh()` method on the texture. * * @param type The type of gradient (linear, radial, etc) * @param dir The direction fo the gradient * @param resolution The quality of the gradient * @param stops The color stops in the gradient */ constructor(type: GradientType, dir: GradientDirection, resolution: number, ...stops: ColorStop[]); /** * Regenerates the gradient image. * * @returns A promise which is resolved when the gradient has been loaded into the texture's image. */ refresh(): Promise<void>; /** * Creates the canvas gradient fill for this {@link GradientTexture}. * * @returns The created gradient and dimensions of the gradient */ createGradient(): { gradient: CanvasGradient; width: number; height: number; }; }