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.7 kB
{"version":3,"file":"sortMixin.mjs","sources":["../../../../src/scene/container/container-mixins/sortMixin.ts"],"sourcesContent":["import type { Container } from '../Container';\n\n/** @ignore */\nexport interface SortMixinConstructor\n{\n /**\n * The zIndex of the container.\n *\n * Controls the rendering order of children within their parent container.\n *\n * A higher value will mean it will be moved towards the front of the rendering order.\n * @example\n * ```ts\n * // Add in any order\n * container.addChild(character, background, foreground);\n *\n * // Adjust rendering order\n * background.zIndex = 0;\n * character.zIndex = 1;\n * foreground.zIndex = 2;\n * ```\n * @see {@link Container#sortableChildren} For enabling sorting\n * @see {@link Container#sortChildren} For manual sorting\n * @default 0\n */\n zIndex?: number;\n /**\n * Should children be sorted by zIndex at the next render call.\n *\n * Will get automatically set to true if a new child is added, or if a child's zIndex changes.\n * @default false\n * @internal\n */\n sortDirty?: boolean;\n /**\n * If set to true, the container will sort its children by `zIndex` value\n * when the next render is called, or manually if `sortChildren()` is called.\n *\n * This actually changes the order of elements in the array of children,\n * so it will affect the rendering order.\n *\n * > [!NOTE] Also be aware of that this may not work nicely with the `addChildAt()` function,\n * > as the `zIndex` sorting may cause the child to automatically sorted to another position.\n * @example\n * ```ts\n * container.sortableChildren = true;\n * ```\n * @default false\n */\n sortableChildren?: boolean;\n}\n\n/**\n * The SortMixin interface provides methods and properties for sorting children of a container\n * based on their `zIndex` values. It allows for automatic sorting of children when their `zIndex`\n * changes or when new children are added. The mixin includes properties to manage sorting state\n * and methods to sort children explicitly.\n * @category scene\n * @advanced\n */\nexport interface SortMixin extends Required<SortMixinConstructor>\n{\n /** @internal */\n _zIndex: number;\n /**\n * Sorts children by zIndex value. Only sorts if container is marked as dirty.\n * @example\n * ```ts\n * // Basic sorting\n * particles.zIndex = 2; // Will mark as dirty\n * container.sortChildren();\n * ```\n * @see {@link Container#sortableChildren} For enabling automatic sorting\n * @see {@link Container#zIndex} For setting child order\n */\n sortChildren: () => void;\n /** @internal */\n depthOfChildModified: () => void;\n}\n\n/** @internal */\nexport const sortMixin: Partial<Container> = {\n _zIndex: 0,\n sortDirty: false,\n sortableChildren: false,\n\n get zIndex()\n {\n return this._zIndex;\n },\n\n set zIndex(value: number)\n {\n if (this._zIndex === value) return;\n\n this._zIndex = value;\n\n this.depthOfChildModified();\n },\n\n depthOfChildModified()\n {\n if (this.parent)\n {\n this.parent.sortableChildren = true;\n this.parent.sortDirty = true;\n }\n\n if (this.parentRenderGroup)\n {\n this.parentRenderGroup.structureDidChange = true;\n }\n },\n\n sortChildren()\n {\n if (!this.sortDirty) return;\n\n this.sortDirty = false;\n\n this.children.sort(sortChildren);\n },\n} as Container;\n\nfunction sortChildren(a: Container, b: Container): number\n{\n return a._zIndex - b._zIndex;\n}\n"],"names":[],"mappings":";AAiFO,MAAM,SAAgC,GAAA;AAAA,EACzC,OAAS,EAAA,CAAA;AAAA,EACT,SAAW,EAAA,KAAA;AAAA,EACX,gBAAkB,EAAA,KAAA;AAAA,EAElB,IAAI,MACJ,GAAA;AACI,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GAChB;AAAA,EAEA,IAAI,OAAO,KACX,EAAA;AACI,IAAA,IAAI,KAAK,OAAY,KAAA,KAAA;AAAO,MAAA,OAAA;AAE5B,IAAA,IAAA,CAAK,OAAU,GAAA,KAAA,CAAA;AAEf,IAAA,IAAA,CAAK,oBAAqB,EAAA,CAAA;AAAA,GAC9B;AAAA,EAEA,oBACA,GAAA;AACI,IAAA,IAAI,KAAK,MACT,EAAA;AACI,MAAA,IAAA,CAAK,OAAO,gBAAmB,GAAA,IAAA,CAAA;AAC/B,MAAA,IAAA,CAAK,OAAO,SAAY,GAAA,IAAA,CAAA;AAAA,KAC5B;AAEA,IAAA,IAAI,KAAK,iBACT,EAAA;AACI,MAAA,IAAA,CAAK,kBAAkB,kBAAqB,GAAA,IAAA,CAAA;AAAA,KAChD;AAAA,GACJ;AAAA,EAEA,YACA,GAAA;AACI,IAAA,IAAI,CAAC,IAAK,CAAA,SAAA;AAAW,MAAA,OAAA;AAErB,IAAA,IAAA,CAAK,SAAY,GAAA,KAAA,CAAA;AAEjB,IAAK,IAAA,CAAA,QAAA,CAAS,KAAK,YAAY,CAAA,CAAA;AAAA,GACnC;AACJ,EAAA;AAEA,SAAS,YAAA,CAAa,GAAc,CACpC,EAAA;AACI,EAAO,OAAA,CAAA,CAAE,UAAU,CAAE,CAAA,OAAA,CAAA;AACzB;;;;"}