UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

1 lines 4.13 kB
{"version":3,"file":"CullerPlugin.mjs","sources":["../../src/culling/CullerPlugin.ts"],"sourcesContent":["import { ExtensionType } from '../extensions/Extensions';\nimport { Culler } from './Culler';\n\nimport type { ExtensionMetadata } from '../extensions/Extensions';\nimport type { Renderer } from '../rendering/renderers/types';\nimport type { Container } from '../scene/container/Container';\n\n/**\n * An {@link Application} plugin that automatically culls (hides) display objects that are outside\n * the visible screen area. This improves performance by not rendering objects that aren't visible.\n *\n * Key Features:\n * - Automatic culling based on screen boundaries\n * - Configurable culling areas and behavior per container\n * - Can improve rendering performance\n * @example\n * ```ts\n * import { Application, CullerPlugin, Container, Rectangle } from 'pixi.js';\n *\n * // Register the plugin\n * extensions.add(CullerPlugin);\n *\n * // Create application\n * const app = new Application();\n * await app.init({...});\n *\n * // Create a container with culling enabled\n * const container = new Container();\n * container.cullable = true; // Enable culling for this container\n * container.cullableChildren = true; // Enable culling for children (default)\n * app.stage.addChild(container);\n *\n * // Optional: Set custom cull area to avoid expensive bounds calculations\n * container.cullArea = new Rectangle(0, 0, app.screen.width, app.screen.height);\n *\n * // Add many sprites to the group\n * for (let j = 0; j < 100; j++) {\n * const sprite = Sprite.from('texture.png');\n * sprite.x = Math.random() * 2000;\n * sprite.y = Math.random() * 2000;\n *\n * sprite.cullable = true; // Enable culling for each sprite\n *\n * // Set cullArea if needed\n * // sprite.cullArea = new Rectangle(0, 0, 100, 100); // Optional\n *\n * // Add to container\n * container.addChild(sprite);\n * }\n * ```\n * @remarks\n * To enable culling, you must set the following properties on your containers:\n * - `cullable`: Set to `true` to enable culling for the container\n * - `cullableChildren`: Set to `true` to enable culling for children (default)\n * - `cullArea`: Optional custom Rectangle for culling bounds\n *\n * Performance Tips:\n * - Group objects that are spatially related\n * - Use `cullArea` for containers with many children to avoid bounds calculations\n * - Set `cullableChildren = false` for containers that are always fully visible\n * @category app\n * @standard\n * @see {@link Culler} For the underlying culling implementation\n * @see {@link CullingMixinConstructor} For culling properties documentation\n */\nexport class CullerPlugin\n{\n /** @ignore */\n public static extension: ExtensionMetadata = {\n priority: 10,\n type: ExtensionType.Application,\n name: 'culler',\n };\n\n /** @internal */\n public static renderer: Renderer;\n /** @internal */\n public static stage: Container;\n /** @internal */\n public static render: () => void;\n private static _renderRef: () => void;\n\n /** @internal */\n public static init(): void\n {\n this._renderRef = this.render.bind(this);\n\n this.render = (): void =>\n {\n Culler.shared.cull(this.stage, this.renderer.screen);\n this.renderer.render({ container: this.stage });\n };\n }\n\n /** @internal */\n public static destroy(): void\n {\n this.render = this._renderRef;\n }\n}\n"],"names":[],"mappings":";;;;AAiEO,MAAM,YACb,CAAA;AAAA;AAAA,EAiBI,OAAc,IACd,GAAA;AACI,IAAA,IAAA,CAAK,UAAa,GAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAEvC,IAAA,IAAA,CAAK,SAAS,MACd;AACI,MAAA,MAAA,CAAO,OAAO,IAAK,CAAA,IAAA,CAAK,KAAO,EAAA,IAAA,CAAK,SAAS,MAAM,CAAA,CAAA;AACnD,MAAA,IAAA,CAAK,SAAS,MAAO,CAAA,EAAE,SAAW,EAAA,IAAA,CAAK,OAAO,CAAA,CAAA;AAAA,KAClD,CAAA;AAAA,GACJ;AAAA;AAAA,EAGA,OAAc,OACd,GAAA;AACI,IAAA,IAAA,CAAK,SAAS,IAAK,CAAA,UAAA,CAAA;AAAA,GACvB;AACJ,CAAA;AAAA;AAlCa,YAAA,CAGK,SAA+B,GAAA;AAAA,EACzC,QAAU,EAAA,EAAA;AAAA,EACV,MAAM,aAAc,CAAA,WAAA;AAAA,EACpB,IAAM,EAAA,QAAA;AACV,CAAA;;;;"}