UNPKG

5.58 kBSource Map (JSON)View Raw
1{"version":3,"file":"BackgroundSystem.mjs","sources":["../../src/background/BackgroundSystem.ts"],"sourcesContent":["import { Color } from '@pixi/color';\nimport { extensions, ExtensionType } from '@pixi/extensions';\n\nimport type { ColorSource } from '@pixi/color';\nimport type { ExtensionMetadata } from '@pixi/extensions';\nimport type { ISystem } from '../system/ISystem';\n\n/**\n * Options for the background system.\n * @memberof PIXI\n * @deprecated since 7.2.3\n * @see PIXI.BackgroundSystemOptions\n */\nexport type BackgroundSytemOptions = BackgroundSystemOptions;\n\n/**\n * Options for the background system.\n * @memberof PIXI\n */\nexport interface BackgroundSystemOptions\n{\n /**\n * The background color used to clear the canvas. See {@link PIXI.ColorSource} for accepted color values.\n * @memberof PIXI.IRendererOptions\n */\n backgroundColor: ColorSource;\n /**\n * Alias for {@link PIXI.IRendererOptions.backgroundColor}\n * @memberof PIXI.IRendererOptions\n */\n background?: ColorSource;\n /**\n * Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).\n * @memberof PIXI.IRendererOptions\n */\n backgroundAlpha: number;\n /**\n * Whether to clear the canvas before new render passes.\n * @memberof PIXI.IRendererOptions\n */\n clearBeforeRender: boolean;\n}\n\n/**\n * The background system manages the background color and alpha of the main view.\n * @memberof PIXI\n */\nexport class BackgroundSystem implements ISystem<BackgroundSystemOptions>\n{\n static defaultOptions: BackgroundSystemOptions = {\n /**\n * {@link PIXI.IRendererOptions.backgroundAlpha}\n * @default 1\n * @memberof PIXI.settings.RENDER_OPTIONS\n */\n backgroundAlpha: 1,\n /**\n * {@link PIXI.IRendererOptions.backgroundColor}\n * @default 0x000000\n * @memberof PIXI.settings.RENDER_OPTIONS\n */\n backgroundColor: 0x0,\n /**\n * {@link PIXI.IRendererOptions.clearBeforeRender}\n * @default true\n * @memberof PIXI.settings.RENDER_OPTIONS\n */\n clearBeforeRender: true,\n };\n\n /** @ignore */\n static extension: ExtensionMetadata = {\n type: [\n ExtensionType.RendererSystem,\n ExtensionType.CanvasRendererSystem\n ],\n name: 'background',\n };\n\n /**\n * This sets if the CanvasRenderer will clear the canvas or not before the new render pass.\n * If the scene is NOT transparent PixiJS will use a canvas sized fillRect operation every\n * frame to set the canvas background color. If the scene is transparent PixiJS will use clearRect\n * to clear the canvas every frame. Disable this by setting this to false. For example, if\n * your game has a canvas filling background image you often don't need this set.\n * @member {boolean}\n * @default\n */\n public clearBeforeRender: boolean;\n\n /** Reference to the internal color */\n private _backgroundColor: Color;\n\n constructor()\n {\n this.clearBeforeRender = true;\n this._backgroundColor = new Color(0x0);\n this.alpha = 1;\n }\n\n /**\n * initiates the background system\n * @param {PIXI.IRendererOptions} options - the options for the background colors\n */\n init(options: BackgroundSystemOptions): void\n {\n this.clearBeforeRender = options.clearBeforeRender;\n const { backgroundColor, background, backgroundAlpha } = options;\n const color = background ?? backgroundColor;\n\n if (color !== undefined)\n {\n this.color = color;\n }\n\n this.alpha = backgroundAlpha;\n }\n\n /**\n * The background color to fill if not transparent.\n * @member {PIXI.ColorSource}\n */\n get color(): ColorSource\n {\n return this._backgroundColor.value;\n }\n\n set color(value: ColorSource)\n {\n this._backgroundColor.setValue(value);\n }\n\n /**\n * The background color alpha. Setting this to 0 will make the canvas transparent.\n * @member {number}\n */\n get alpha(): number\n {\n return this._backgroundColor.alpha;\n }\n\n set alpha(value: number)\n {\n this._backgroundColor.setAlpha(value);\n }\n\n /** The background color object. */\n get backgroundColor(): Color\n {\n return this._backgroundColor;\n }\n\n destroy(): void\n {\n // ka boom!\n }\n}\n\nextensions.add(BackgroundSystem);\n"],"names":[],"mappings":";;AA+CO,MAAM,iBACb;AAAA,EA6CI,cACA;AACS,SAAA,oBAAoB,IACzB,KAAK,mBAAmB,IAAI,MAAM,CAAG,GACrC,KAAK,QAAQ;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,SACL;AACI,SAAK,oBAAoB,QAAQ;AACjC,UAAM,EAAE,iBAAiB,YAAY,oBAAoB,SACnD,QAAQ,cAAc;AAExB,cAAU,WAEV,KAAK,QAAQ,QAGjB,KAAK,QAAQ;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,QACJ;AACI,WAAO,KAAK,iBAAiB;AAAA,EACjC;AAAA,EAEA,IAAI,MAAM,OACV;AACS,SAAA,iBAAiB,SAAS,KAAK;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,QACJ;AACI,WAAO,KAAK,iBAAiB;AAAA,EACjC;AAAA,EAEA,IAAI,MAAM,OACV;AACS,SAAA,iBAAiB,SAAS,KAAK;AAAA,EACxC;AAAA;AAAA,EAGA,IAAI,kBACJ;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,UACA;AAAA,EAEA;AACJ;AA7Ga,iBAEF,iBAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7C,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjB,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjB,mBAAmB;AACvB;AArBS,iBAwBF,YAA+B;AAAA,EAClC,MAAM;AAAA,IACF,cAAc;AAAA,IACd,cAAc;AAAA,EAClB;AAAA,EACA,MAAM;AACV;AAiFJ,WAAW,IAAI,gBAAgB;"}
\No newline at end of file