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.64 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,SAAA,GAAgC;AAAA,EACzC,OAAA,EAAS,CAAA;AAAA,EACT,SAAA,EAAW,KAAA;AAAA,EACX,gBAAA,EAAkB,KAAA;AAAA,EAElB,IAAI,MAAA,GACJ;AACI,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EAChB,CAAA;AAAA,EAEA,IAAI,OAAO,KAAA,EACX;AACI,IAAA,IAAI,IAAA,CAAK,YAAY,KAAA,EAAO;AAE5B,IAAA,IAAA,CAAK,OAAA,GAAU,KAAA;AAEf,IAAA,IAAA,CAAK,oBAAA,EAAqB;AAAA,EAC9B,CAAA;AAAA,EAEA,oBAAA,GACA;AACI,IAAA,IAAI,KAAK,MAAA,EACT;AACI,MAAA,IAAA,CAAK,OAAO,gBAAA,GAAmB,IAAA;AAC/B,MAAA,IAAA,CAAK,OAAO,SAAA,GAAY,IAAA;AAAA,IAC5B;AAEA,IAAA,IAAI,KAAK,iBAAA,EACT;AACI,MAAA,IAAA,CAAK,kBAAkB,kBAAA,GAAqB,IAAA;AAAA,IAChD;AAAA,EACJ,CAAA;AAAA,EAEA,YAAA,GACA;AACI,IAAA,IAAI,CAAC,KAAK,SAAA,EAAW;AAErB,IAAA,IAAA,CAAK,SAAA,GAAY,KAAA;AAEjB,IAAA,IAAA,CAAK,QAAA,CAAS,KAAK,YAAY,CAAA;AAAA,EACnC;AACJ;AAEA,SAAS,YAAA,CAAa,GAAc,CAAA,EACpC;AACI,EAAA,OAAO,CAAA,CAAE,UAAU,CAAA,CAAE,OAAA;AACzB;;;;"}