@pixi/display
Advanced tools
Comparing version 5.0.0-alpha.3 to 5.0.0-rc
/*! | ||
* @pixi/display - v5.0.0-alpha.3 | ||
* Compiled Tue, 03 Jul 2018 04:08:21 UTC | ||
* @pixi/display - v5.0.0-rc | ||
* Compiled Fri, 01 Feb 2019 04:50:10 UTC | ||
* | ||
@@ -8,3 +8,4 @@ * @pixi/display is licensed under the MIT License. | ||
*/ | ||
import { Rectangle, Transform } from '@pixi/math'; | ||
import { settings } from '@pixi/settings'; | ||
import { Rectangle, RAD_TO_DEG, DEG_TO_RAD, Transform } from '@pixi/math'; | ||
import EventEmitter from 'eventemitter3'; | ||
@@ -14,6 +15,28 @@ import removeItems from 'remove-array-items'; | ||
/** | ||
* 'Builder' pattern for bounds rectangles | ||
* Axis-Aligned Bounding Box | ||
* It is not a shape! Its mutable thing, no 'EMPTY' or that kind of problems | ||
* Sets the default value for the container property 'sortableChildren'. | ||
* If set to true, the container will sort its children by zIndex value | ||
* when updateTransform() is called, or manually if sortChildren() is called. | ||
* | ||
* This actually changes the order of elements in the array, so should be treated | ||
* as a basic solution that is not performant compared to other solutions, | ||
* such as @link https://github.com/pixijs/pixi-display | ||
* | ||
* Also be aware of that this may not work nicely with the addChildAt() function, | ||
* as the zIndex sorting may cause the child to automatically sorted to another position. | ||
* | ||
* @static | ||
* @constant | ||
* @name SORTABLE_CHILDREN | ||
* @memberof PIXI.settings | ||
* @type {boolean} | ||
* @default false | ||
*/ | ||
settings.SORTABLE_CHILDREN = false; | ||
/** | ||
* 'Builder' pattern for bounds rectangles. | ||
* | ||
* This could be called an Axis-Aligned Bounding Box. | ||
* It is not an actual shape. It is a mutable thing; no 'EMPTY' or those kind of problems. | ||
* | ||
* @class | ||
@@ -162,3 +185,3 @@ * @memberof PIXI | ||
* | ||
* @param {PIXI.TransformBase} transform - TODO | ||
* @param {PIXI.Transform} transform - TODO | ||
* @param {number} x0 - TODO | ||
@@ -220,9 +243,40 @@ * @param {number} y0 - TODO | ||
/** | ||
* Add an array of vertices | ||
* Adds screen vertices from array | ||
* | ||
* @param {PIXI.TransformBase} transform - TODO | ||
* @param {Float32Array} vertices - TODO | ||
* @param {number} beginOffset - TODO | ||
* @param {number} endOffset - TODO | ||
* @param {Float32Array} vertexData - calculated vertices | ||
* @param {number} beginOffset - begin offset | ||
* @param {number} endOffset - end offset, excluded | ||
*/ | ||
Bounds.prototype.addVertexData = function addVertexData (vertexData, beginOffset, endOffset) | ||
{ | ||
var minX = this.minX; | ||
var minY = this.minY; | ||
var maxX = this.maxX; | ||
var maxY = this.maxY; | ||
for (var i = beginOffset; i < endOffset; i += 2) | ||
{ | ||
var x = vertexData[i]; | ||
var y = vertexData[i + 1]; | ||
minX = x < minX ? x : minX; | ||
minY = y < minY ? y : minY; | ||
maxX = x > maxX ? x : maxX; | ||
maxY = y > maxY ? y : maxY; | ||
} | ||
this.minX = minX; | ||
this.minY = minY; | ||
this.maxX = maxX; | ||
this.maxY = maxY; | ||
}; | ||
/** | ||
* Add an array of mesh vertices | ||
* | ||
* @param {PIXI.Transform} transform - mesh transform | ||
* @param {Float32Array} vertices - mesh coordinates in array | ||
* @param {number} beginOffset - begin offset | ||
* @param {number} endOffset - end offset, excluded | ||
*/ | ||
Bounds.prototype.addVertices = function addVertices (transform, vertices, beginOffset, endOffset) | ||
@@ -338,9 +392,10 @@ { | ||
* The base class for all objects that are rendered on the screen. | ||
* This is an abstract class and should not be used on its own rather it should be extended. | ||
* | ||
* This is an abstract class and should not be used on its own; rather it should be extended. | ||
* | ||
* @class | ||
* @extends EventEmitter | ||
* @extends PIXI.utils.EventEmitter | ||
* @memberof PIXI | ||
*/ | ||
var DisplayObject = (function (EventEmitter$$1) { | ||
var DisplayObject = /*@__PURE__*/(function (EventEmitter$$1) { | ||
function DisplayObject() | ||
@@ -357,3 +412,3 @@ { | ||
* | ||
* @member {PIXI.TransformBase} | ||
* @member {PIXI.Transform} | ||
*/ | ||
@@ -406,2 +461,20 @@ this.transform = new Transform(); | ||
/** | ||
* Which index in the children array the display component was before the previous zIndex sort. | ||
* Used by containers to help sort objects with the same zIndex, by using previous array index as the decider. | ||
* | ||
* @member {number} | ||
* @protected | ||
*/ | ||
this._lastSortedIndex = 0; | ||
/** | ||
* The zIndex of the displayObject. | ||
* A higher value will mean it will be rendered on top of other displayObjects within the same container. | ||
* | ||
* @member {number} | ||
* @protected | ||
*/ | ||
this._zIndex = 0; | ||
/** | ||
* The area the filter is applied to. This is used as more of an optimization | ||
@@ -412,3 +485,3 @@ * rather than figuring out the dimensions of the displayObject each frame you can set this rectangle. | ||
* | ||
* @member {PIXI.Rectangle} | ||
* @member {?PIXI.Rectangle} | ||
*/ | ||
@@ -422,3 +495,3 @@ this.filterArea = null; | ||
* | ||
* @member {PIXI.Filter[]} | ||
* @member {?PIXI.Filter[]} | ||
*/ | ||
@@ -431,4 +504,4 @@ this.filters = null; | ||
* | ||
* @member {PIXI.Rectangle} | ||
* @private | ||
* @member {PIXI.Bounds} | ||
* @protected | ||
*/ | ||
@@ -445,3 +518,3 @@ this._bounds = new Bounds(); | ||
* @member {PIXI.Graphics|PIXI.Sprite} | ||
* @private | ||
* @protected | ||
*/ | ||
@@ -451,11 +524,2 @@ this._mask = null; | ||
/** | ||
* If the object has been destroyed via destroy(). If true, it should not be used. | ||
* | ||
* @member {boolean} | ||
* @private | ||
* @readonly | ||
*/ | ||
this._destroyed = false; | ||
/** | ||
* Fired when this DisplayObject is added to a Container. | ||
@@ -473,2 +537,16 @@ * | ||
*/ | ||
/** | ||
* If the object has been destroyed via destroy(). If true, it should not be used. | ||
* | ||
* @member {boolean} | ||
* @protected | ||
*/ | ||
this._destroyed = false; | ||
/** | ||
* used to fast check if a sprite is.. a sprite! | ||
* @member {boolean} | ||
*/ | ||
this.isSprite = false; | ||
} | ||
@@ -480,6 +558,6 @@ | ||
var prototypeAccessors = { _tempDisplayObjectParent: { configurable: true },x: { configurable: true },y: { configurable: true },worldTransform: { configurable: true },localTransform: { configurable: true },position: { configurable: true },scale: { configurable: true },pivot: { configurable: true },skew: { configurable: true },rotation: { configurable: true },worldVisible: { configurable: true },mask: { configurable: true } }; | ||
var prototypeAccessors = { _tempDisplayObjectParent: { configurable: true },x: { configurable: true },y: { configurable: true },worldTransform: { configurable: true },localTransform: { configurable: true },position: { configurable: true },scale: { configurable: true },pivot: { configurable: true },skew: { configurable: true },rotation: { configurable: true },angle: { configurable: true },zIndex: { configurable: true },worldVisible: { configurable: true },mask: { configurable: true } }; | ||
/** | ||
* @private | ||
* @protected | ||
* @member {PIXI.DisplayObject} | ||
@@ -531,6 +609,6 @@ */ | ||
* | ||
* @param {boolean} skipUpdate - Setting to `true` will stop the transforms of the scene graph from | ||
* @param {boolean} [skipUpdate] - Setting to `true` will stop the transforms of the scene graph from | ||
* being updated. This means the calculation returned MAY be out of date BUT will give you a | ||
* nice performance boost. | ||
* @param {PIXI.Rectangle} rect - Optional rectangle to store the result of the bounds calculation. | ||
* @param {PIXI.Rectangle} [rect] - Optional rectangle to store the result of the bounds calculation. | ||
* @return {PIXI.Rectangle} The rectangular bounding area. | ||
@@ -608,7 +686,7 @@ */ | ||
* | ||
* @param {PIXI.Point} position - The world origin to calculate from. | ||
* @param {PIXI.Point} [point] - A Point object in which to store the value, optional | ||
* @param {PIXI.IPoint} position - The world origin to calculate from. | ||
* @param {PIXI.IPoint} [point] - A Point object in which to store the value, optional | ||
* (otherwise will create a new Point). | ||
* @param {boolean} [skipUpdate=false] - Should we skip the update transform. | ||
* @return {PIXI.Point} A point object representing the position of this object. | ||
* @return {PIXI.IPoint} A point object representing the position of this object. | ||
*/ | ||
@@ -645,8 +723,8 @@ DisplayObject.prototype.toGlobal = function toGlobal (position, point, skipUpdate) | ||
* | ||
* @param {PIXI.Point} position - The world origin to calculate from. | ||
* @param {PIXI.IPoint} position - The world origin to calculate from. | ||
* @param {PIXI.DisplayObject} [from] - The DisplayObject to calculate the global position from. | ||
* @param {PIXI.Point} [point] - A Point object in which to store the value, optional | ||
* @param {PIXI.IPoint} [point] - A Point object in which to store the value, optional | ||
* (otherwise will create a new Point). | ||
* @param {boolean} [skipUpdate=false] - Should we skip the update transform | ||
* @return {PIXI.Point} A point object representing the position of this object | ||
* @return {PIXI.IPoint} A point object representing the position of this object | ||
*/ | ||
@@ -838,3 +916,3 @@ DisplayObject.prototype.toLocal = function toLocal (position, from, point, skipUpdate) | ||
* | ||
* @member {PIXI.Point|PIXI.ObservablePoint} | ||
* @member {PIXI.IPoint} | ||
*/ | ||
@@ -855,3 +933,3 @@ prototypeAccessors.position.get = function () | ||
* | ||
* @member {PIXI.Point|PIXI.ObservablePoint} | ||
* @member {PIXI.IPoint} | ||
*/ | ||
@@ -872,3 +950,3 @@ prototypeAccessors.scale.get = function () | ||
* | ||
* @member {PIXI.Point|PIXI.ObservablePoint} | ||
* @member {PIXI.IPoint} | ||
*/ | ||
@@ -903,2 +981,3 @@ prototypeAccessors.pivot.get = function () | ||
* The rotation of the object in radians. | ||
* 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees. | ||
* | ||
@@ -918,2 +997,40 @@ * @member {number} | ||
/** | ||
* The angle of the object in degrees. | ||
* 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees. | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.angle.get = function () | ||
{ | ||
return this.transform.rotation * RAD_TO_DEG; | ||
}; | ||
prototypeAccessors.angle.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this.transform.rotation = value * DEG_TO_RAD; | ||
}; | ||
/** | ||
* The zIndex of the displayObject. | ||
* If a container has the sortableChildren property set to true, children will be automatically | ||
* sorted by zIndex value; a higher value will mean it will be moved towards the end of the array, | ||
* and thus rendered on top of other displayObjects within the same container. | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.zIndex.get = function () | ||
{ | ||
return this._zIndex; | ||
}; | ||
prototypeAccessors.zIndex.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this._zIndex = value; | ||
if (this.parent) | ||
{ | ||
this.parent.sortDirty = true; | ||
} | ||
}; | ||
/** | ||
* Indicates if the object is globally visible. | ||
@@ -943,3 +1060,3 @@ * | ||
* Sets a mask for the displayObject. A mask is an object that limits the visibility of an | ||
* object to the shape of the mask applied to it. In PIXI a regular mask must be a | ||
* object to the shape of the mask applied to it. In PixiJS a regular mask must be a | ||
* {@link PIXI.Graphics} or a {@link PIXI.Sprite} object. This allows for much faster masking in canvas as it | ||
@@ -991,6 +1108,17 @@ * utilities shape clipping. To remove a mask, set this property to `null`. | ||
function sortChildren(a, b) | ||
{ | ||
if (a.zIndex === b.zIndex) | ||
{ | ||
return a._lastSortedIndex - b._lastSortedIndex; | ||
} | ||
return a.zIndex - b.zIndex; | ||
} | ||
/** | ||
* A Container represents a collection of display objects. | ||
* It is the base class of all display objects that act as a container for other objects. | ||
* | ||
* It is the base class of all display objects that act as a container for other objects (like Sprites). | ||
* | ||
*```js | ||
@@ -1005,3 +1133,3 @@ * let container = new PIXI.Container(); | ||
*/ | ||
var Container = (function (DisplayObject$$1) { | ||
var Container = /*@__PURE__*/(function (DisplayObject$$1) { | ||
function Container() | ||
@@ -1018,2 +1146,27 @@ { | ||
this.children = []; | ||
/** | ||
* If set to true, the container will sort its children by zIndex value | ||
* when updateTransform() is called, or manually if sortChildren() is called. | ||
* | ||
* This actually changes the order of elements in the array, so should be treated | ||
* as a basic solution that is not performant compared to other solutions, | ||
* such as @link https://github.com/pixijs/pixi-display | ||
* | ||
* Also be aware of that this may not work nicely with the addChildAt() function, | ||
* as the zIndex sorting may cause the child to automatically sorted to another position. | ||
* | ||
* @see PIXI.settings.SORTABLE_CHILDREN | ||
* | ||
* @member {boolean} | ||
*/ | ||
this.sortableChildren = settings.SORTABLE_CHILDREN; | ||
/** | ||
* Should children be sorted by zIndex at the next updateTransform call. | ||
* Will get automatically set to true if a new child is added, or if a child's zIndex changes. | ||
* | ||
* @member {boolean} | ||
*/ | ||
this.sortDirty = false; | ||
} | ||
@@ -1030,3 +1183,3 @@ | ||
* | ||
* @private | ||
* @protected | ||
*/ | ||
@@ -1049,3 +1202,2 @@ Container.prototype.onChildrenChange = function onChildrenChange () | ||
var arguments$1 = arguments; | ||
var this$1 = this; | ||
@@ -1061,3 +1213,3 @@ var argumentsLength = arguments.length; | ||
{ | ||
this$1.addChild(arguments$1[i]); | ||
this.addChild(arguments$1[i]); | ||
} | ||
@@ -1074,2 +1226,4 @@ } | ||
child.parent = this; | ||
this.sortDirty = true; | ||
// ensure child transform will be recalculated | ||
@@ -1111,2 +1265,4 @@ child.transform._parentID = -1; | ||
child.parent = this; | ||
this.sortDirty = true; | ||
// ensure child transform will be recalculated | ||
@@ -1212,3 +1368,2 @@ child.transform._parentID = -1; | ||
var arguments$1 = arguments; | ||
var this$1 = this; | ||
@@ -1224,3 +1379,3 @@ var argumentsLength = arguments.length; | ||
{ | ||
this$1.removeChild(arguments$1[i]); | ||
this.removeChild(arguments$1[i]); | ||
} | ||
@@ -1284,3 +1439,2 @@ } | ||
{ | ||
var this$1 = this; | ||
if ( beginIndex === void 0 ) beginIndex = 0; | ||
@@ -1312,3 +1466,3 @@ | ||
{ | ||
removed[i$1].emit('removed', this$1); | ||
removed[i$1].emit('removed', this); | ||
} | ||
@@ -1327,2 +1481,29 @@ | ||
/** | ||
* Sorts children by zIndex. Previous order is mantained for 2 children with the same zIndex. | ||
*/ | ||
Container.prototype.sortChildren = function sortChildren$1 () | ||
{ | ||
var sortRequired = false; | ||
for (var i = 0, j = this.children.length; i < j; ++i) | ||
{ | ||
var child = this.children[i]; | ||
child._lastSortedIndex = i; | ||
if (!sortRequired && child.zIndex !== 0) | ||
{ | ||
sortRequired = true; | ||
} | ||
} | ||
if (sortRequired && this.children.length > 1) | ||
{ | ||
this.children.sort(sortChildren); | ||
} | ||
this.sortDirty = false; | ||
}; | ||
/** | ||
* Updates the transform on all children of this container for rendering | ||
@@ -1332,3 +1513,6 @@ */ | ||
{ | ||
var this$1 = this; | ||
if (this.sortableChildren && this.sortDirty) | ||
{ | ||
this.sortChildren(); | ||
} | ||
@@ -1344,3 +1528,3 @@ this._boundsID++; | ||
{ | ||
var child = this$1.children[i]; | ||
var child = this.children[i]; | ||
@@ -1360,4 +1544,2 @@ if (child.visible) | ||
{ | ||
var this$1 = this; | ||
this._bounds.clear(); | ||
@@ -1369,3 +1551,3 @@ | ||
{ | ||
var child = this$1.children[i]; | ||
var child = this.children[i]; | ||
@@ -1383,11 +1565,11 @@ if (!child.visible || !child.renderable) | ||
child._mask.calculateBounds(); | ||
this$1._bounds.addBoundsMask(child._bounds, child._mask._bounds); | ||
this._bounds.addBoundsMask(child._bounds, child._mask._bounds); | ||
} | ||
else if (child.filterArea) | ||
{ | ||
this$1._bounds.addBoundsArea(child._bounds, child.filterArea); | ||
this._bounds.addBoundsArea(child._bounds, child.filterArea); | ||
} | ||
else | ||
{ | ||
this$1._bounds.addBounds(child._bounds); | ||
this._bounds.addBounds(child._bounds); | ||
} | ||
@@ -1403,2 +1585,3 @@ } | ||
* | ||
* @protected | ||
*/ | ||
@@ -1417,4 +1600,2 @@ Container.prototype._calculateBounds = function _calculateBounds () | ||
{ | ||
var this$1 = this; | ||
// if the object is not visible or the alpha is 0 then no need to render this element | ||
@@ -1438,3 +1619,3 @@ if (!this.visible || this.worldAlpha <= 0 || !this.renderable) | ||
{ | ||
this$1.children[i].render(renderer); | ||
this.children[i].render(renderer); | ||
} | ||
@@ -1447,3 +1628,3 @@ } | ||
* | ||
* @private | ||
* @protected | ||
* @param {PIXI.Renderer} renderer - The renderer | ||
@@ -1453,4 +1634,2 @@ */ | ||
{ | ||
var this$1 = this; | ||
renderer.batch.flush(); | ||
@@ -1475,3 +1654,3 @@ | ||
{ | ||
this$1._enabledFilters.push(filters[i]); | ||
this._enabledFilters.push(filters[i]); | ||
} | ||
@@ -1497,3 +1676,3 @@ } | ||
{ | ||
this$1.children[i$1].render(renderer); | ||
this.children[i$1].render(renderer); | ||
} | ||
@@ -1517,3 +1696,3 @@ | ||
* | ||
* @private | ||
* @protected | ||
* @param {PIXI.Renderer} renderer - The renderer | ||
@@ -1543,2 +1722,4 @@ */ | ||
this.sortDirty = false; | ||
var destroyChildren = typeof options === 'boolean' ? options : options && options.children; | ||
@@ -1545,0 +1726,0 @@ |
/*! | ||
* @pixi/display - v5.0.0-alpha.3 | ||
* Compiled Tue, 03 Jul 2018 04:08:21 UTC | ||
* @pixi/display - v5.0.0-rc | ||
* Compiled Fri, 01 Feb 2019 04:50:10 UTC | ||
* | ||
@@ -14,2 +14,3 @@ * @pixi/display is licensed under the MIT License. | ||
var settings = require('@pixi/settings'); | ||
var math = require('@pixi/math'); | ||
@@ -20,6 +21,28 @@ var EventEmitter = _interopDefault(require('eventemitter3')); | ||
/** | ||
* 'Builder' pattern for bounds rectangles | ||
* Axis-Aligned Bounding Box | ||
* It is not a shape! Its mutable thing, no 'EMPTY' or that kind of problems | ||
* Sets the default value for the container property 'sortableChildren'. | ||
* If set to true, the container will sort its children by zIndex value | ||
* when updateTransform() is called, or manually if sortChildren() is called. | ||
* | ||
* This actually changes the order of elements in the array, so should be treated | ||
* as a basic solution that is not performant compared to other solutions, | ||
* such as @link https://github.com/pixijs/pixi-display | ||
* | ||
* Also be aware of that this may not work nicely with the addChildAt() function, | ||
* as the zIndex sorting may cause the child to automatically sorted to another position. | ||
* | ||
* @static | ||
* @constant | ||
* @name SORTABLE_CHILDREN | ||
* @memberof PIXI.settings | ||
* @type {boolean} | ||
* @default false | ||
*/ | ||
settings.settings.SORTABLE_CHILDREN = false; | ||
/** | ||
* 'Builder' pattern for bounds rectangles. | ||
* | ||
* This could be called an Axis-Aligned Bounding Box. | ||
* It is not an actual shape. It is a mutable thing; no 'EMPTY' or those kind of problems. | ||
* | ||
* @class | ||
@@ -168,3 +191,3 @@ * @memberof PIXI | ||
* | ||
* @param {PIXI.TransformBase} transform - TODO | ||
* @param {PIXI.Transform} transform - TODO | ||
* @param {number} x0 - TODO | ||
@@ -226,9 +249,40 @@ * @param {number} y0 - TODO | ||
/** | ||
* Add an array of vertices | ||
* Adds screen vertices from array | ||
* | ||
* @param {PIXI.TransformBase} transform - TODO | ||
* @param {Float32Array} vertices - TODO | ||
* @param {number} beginOffset - TODO | ||
* @param {number} endOffset - TODO | ||
* @param {Float32Array} vertexData - calculated vertices | ||
* @param {number} beginOffset - begin offset | ||
* @param {number} endOffset - end offset, excluded | ||
*/ | ||
Bounds.prototype.addVertexData = function addVertexData (vertexData, beginOffset, endOffset) | ||
{ | ||
var minX = this.minX; | ||
var minY = this.minY; | ||
var maxX = this.maxX; | ||
var maxY = this.maxY; | ||
for (var i = beginOffset; i < endOffset; i += 2) | ||
{ | ||
var x = vertexData[i]; | ||
var y = vertexData[i + 1]; | ||
minX = x < minX ? x : minX; | ||
minY = y < minY ? y : minY; | ||
maxX = x > maxX ? x : maxX; | ||
maxY = y > maxY ? y : maxY; | ||
} | ||
this.minX = minX; | ||
this.minY = minY; | ||
this.maxX = maxX; | ||
this.maxY = maxY; | ||
}; | ||
/** | ||
* Add an array of mesh vertices | ||
* | ||
* @param {PIXI.Transform} transform - mesh transform | ||
* @param {Float32Array} vertices - mesh coordinates in array | ||
* @param {number} beginOffset - begin offset | ||
* @param {number} endOffset - end offset, excluded | ||
*/ | ||
Bounds.prototype.addVertices = function addVertices (transform, vertices, beginOffset, endOffset) | ||
@@ -344,9 +398,10 @@ { | ||
* The base class for all objects that are rendered on the screen. | ||
* This is an abstract class and should not be used on its own rather it should be extended. | ||
* | ||
* This is an abstract class and should not be used on its own; rather it should be extended. | ||
* | ||
* @class | ||
* @extends EventEmitter | ||
* @extends PIXI.utils.EventEmitter | ||
* @memberof PIXI | ||
*/ | ||
var DisplayObject = (function (EventEmitter$$1) { | ||
var DisplayObject = /*@__PURE__*/(function (EventEmitter$$1) { | ||
function DisplayObject() | ||
@@ -363,3 +418,3 @@ { | ||
* | ||
* @member {PIXI.TransformBase} | ||
* @member {PIXI.Transform} | ||
*/ | ||
@@ -412,2 +467,20 @@ this.transform = new math.Transform(); | ||
/** | ||
* Which index in the children array the display component was before the previous zIndex sort. | ||
* Used by containers to help sort objects with the same zIndex, by using previous array index as the decider. | ||
* | ||
* @member {number} | ||
* @protected | ||
*/ | ||
this._lastSortedIndex = 0; | ||
/** | ||
* The zIndex of the displayObject. | ||
* A higher value will mean it will be rendered on top of other displayObjects within the same container. | ||
* | ||
* @member {number} | ||
* @protected | ||
*/ | ||
this._zIndex = 0; | ||
/** | ||
* The area the filter is applied to. This is used as more of an optimization | ||
@@ -418,3 +491,3 @@ * rather than figuring out the dimensions of the displayObject each frame you can set this rectangle. | ||
* | ||
* @member {PIXI.Rectangle} | ||
* @member {?PIXI.Rectangle} | ||
*/ | ||
@@ -428,3 +501,3 @@ this.filterArea = null; | ||
* | ||
* @member {PIXI.Filter[]} | ||
* @member {?PIXI.Filter[]} | ||
*/ | ||
@@ -437,4 +510,4 @@ this.filters = null; | ||
* | ||
* @member {PIXI.Rectangle} | ||
* @private | ||
* @member {PIXI.Bounds} | ||
* @protected | ||
*/ | ||
@@ -451,3 +524,3 @@ this._bounds = new Bounds(); | ||
* @member {PIXI.Graphics|PIXI.Sprite} | ||
* @private | ||
* @protected | ||
*/ | ||
@@ -457,11 +530,2 @@ this._mask = null; | ||
/** | ||
* If the object has been destroyed via destroy(). If true, it should not be used. | ||
* | ||
* @member {boolean} | ||
* @private | ||
* @readonly | ||
*/ | ||
this._destroyed = false; | ||
/** | ||
* Fired when this DisplayObject is added to a Container. | ||
@@ -479,2 +543,16 @@ * | ||
*/ | ||
/** | ||
* If the object has been destroyed via destroy(). If true, it should not be used. | ||
* | ||
* @member {boolean} | ||
* @protected | ||
*/ | ||
this._destroyed = false; | ||
/** | ||
* used to fast check if a sprite is.. a sprite! | ||
* @member {boolean} | ||
*/ | ||
this.isSprite = false; | ||
} | ||
@@ -486,6 +564,6 @@ | ||
var prototypeAccessors = { _tempDisplayObjectParent: { configurable: true },x: { configurable: true },y: { configurable: true },worldTransform: { configurable: true },localTransform: { configurable: true },position: { configurable: true },scale: { configurable: true },pivot: { configurable: true },skew: { configurable: true },rotation: { configurable: true },worldVisible: { configurable: true },mask: { configurable: true } }; | ||
var prototypeAccessors = { _tempDisplayObjectParent: { configurable: true },x: { configurable: true },y: { configurable: true },worldTransform: { configurable: true },localTransform: { configurable: true },position: { configurable: true },scale: { configurable: true },pivot: { configurable: true },skew: { configurable: true },rotation: { configurable: true },angle: { configurable: true },zIndex: { configurable: true },worldVisible: { configurable: true },mask: { configurable: true } }; | ||
/** | ||
* @private | ||
* @protected | ||
* @member {PIXI.DisplayObject} | ||
@@ -537,6 +615,6 @@ */ | ||
* | ||
* @param {boolean} skipUpdate - Setting to `true` will stop the transforms of the scene graph from | ||
* @param {boolean} [skipUpdate] - Setting to `true` will stop the transforms of the scene graph from | ||
* being updated. This means the calculation returned MAY be out of date BUT will give you a | ||
* nice performance boost. | ||
* @param {PIXI.Rectangle} rect - Optional rectangle to store the result of the bounds calculation. | ||
* @param {PIXI.Rectangle} [rect] - Optional rectangle to store the result of the bounds calculation. | ||
* @return {PIXI.Rectangle} The rectangular bounding area. | ||
@@ -614,7 +692,7 @@ */ | ||
* | ||
* @param {PIXI.Point} position - The world origin to calculate from. | ||
* @param {PIXI.Point} [point] - A Point object in which to store the value, optional | ||
* @param {PIXI.IPoint} position - The world origin to calculate from. | ||
* @param {PIXI.IPoint} [point] - A Point object in which to store the value, optional | ||
* (otherwise will create a new Point). | ||
* @param {boolean} [skipUpdate=false] - Should we skip the update transform. | ||
* @return {PIXI.Point} A point object representing the position of this object. | ||
* @return {PIXI.IPoint} A point object representing the position of this object. | ||
*/ | ||
@@ -651,8 +729,8 @@ DisplayObject.prototype.toGlobal = function toGlobal (position, point, skipUpdate) | ||
* | ||
* @param {PIXI.Point} position - The world origin to calculate from. | ||
* @param {PIXI.IPoint} position - The world origin to calculate from. | ||
* @param {PIXI.DisplayObject} [from] - The DisplayObject to calculate the global position from. | ||
* @param {PIXI.Point} [point] - A Point object in which to store the value, optional | ||
* @param {PIXI.IPoint} [point] - A Point object in which to store the value, optional | ||
* (otherwise will create a new Point). | ||
* @param {boolean} [skipUpdate=false] - Should we skip the update transform | ||
* @return {PIXI.Point} A point object representing the position of this object | ||
* @return {PIXI.IPoint} A point object representing the position of this object | ||
*/ | ||
@@ -844,3 +922,3 @@ DisplayObject.prototype.toLocal = function toLocal (position, from, point, skipUpdate) | ||
* | ||
* @member {PIXI.Point|PIXI.ObservablePoint} | ||
* @member {PIXI.IPoint} | ||
*/ | ||
@@ -861,3 +939,3 @@ prototypeAccessors.position.get = function () | ||
* | ||
* @member {PIXI.Point|PIXI.ObservablePoint} | ||
* @member {PIXI.IPoint} | ||
*/ | ||
@@ -878,3 +956,3 @@ prototypeAccessors.scale.get = function () | ||
* | ||
* @member {PIXI.Point|PIXI.ObservablePoint} | ||
* @member {PIXI.IPoint} | ||
*/ | ||
@@ -909,2 +987,3 @@ prototypeAccessors.pivot.get = function () | ||
* The rotation of the object in radians. | ||
* 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees. | ||
* | ||
@@ -924,2 +1003,40 @@ * @member {number} | ||
/** | ||
* The angle of the object in degrees. | ||
* 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees. | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.angle.get = function () | ||
{ | ||
return this.transform.rotation * math.RAD_TO_DEG; | ||
}; | ||
prototypeAccessors.angle.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this.transform.rotation = value * math.DEG_TO_RAD; | ||
}; | ||
/** | ||
* The zIndex of the displayObject. | ||
* If a container has the sortableChildren property set to true, children will be automatically | ||
* sorted by zIndex value; a higher value will mean it will be moved towards the end of the array, | ||
* and thus rendered on top of other displayObjects within the same container. | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.zIndex.get = function () | ||
{ | ||
return this._zIndex; | ||
}; | ||
prototypeAccessors.zIndex.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this._zIndex = value; | ||
if (this.parent) | ||
{ | ||
this.parent.sortDirty = true; | ||
} | ||
}; | ||
/** | ||
* Indicates if the object is globally visible. | ||
@@ -949,3 +1066,3 @@ * | ||
* Sets a mask for the displayObject. A mask is an object that limits the visibility of an | ||
* object to the shape of the mask applied to it. In PIXI a regular mask must be a | ||
* object to the shape of the mask applied to it. In PixiJS a regular mask must be a | ||
* {@link PIXI.Graphics} or a {@link PIXI.Sprite} object. This allows for much faster masking in canvas as it | ||
@@ -997,6 +1114,17 @@ * utilities shape clipping. To remove a mask, set this property to `null`. | ||
function sortChildren(a, b) | ||
{ | ||
if (a.zIndex === b.zIndex) | ||
{ | ||
return a._lastSortedIndex - b._lastSortedIndex; | ||
} | ||
return a.zIndex - b.zIndex; | ||
} | ||
/** | ||
* A Container represents a collection of display objects. | ||
* It is the base class of all display objects that act as a container for other objects. | ||
* | ||
* It is the base class of all display objects that act as a container for other objects (like Sprites). | ||
* | ||
*```js | ||
@@ -1011,3 +1139,3 @@ * let container = new PIXI.Container(); | ||
*/ | ||
var Container = (function (DisplayObject$$1) { | ||
var Container = /*@__PURE__*/(function (DisplayObject$$1) { | ||
function Container() | ||
@@ -1024,2 +1152,27 @@ { | ||
this.children = []; | ||
/** | ||
* If set to true, the container will sort its children by zIndex value | ||
* when updateTransform() is called, or manually if sortChildren() is called. | ||
* | ||
* This actually changes the order of elements in the array, so should be treated | ||
* as a basic solution that is not performant compared to other solutions, | ||
* such as @link https://github.com/pixijs/pixi-display | ||
* | ||
* Also be aware of that this may not work nicely with the addChildAt() function, | ||
* as the zIndex sorting may cause the child to automatically sorted to another position. | ||
* | ||
* @see PIXI.settings.SORTABLE_CHILDREN | ||
* | ||
* @member {boolean} | ||
*/ | ||
this.sortableChildren = settings.settings.SORTABLE_CHILDREN; | ||
/** | ||
* Should children be sorted by zIndex at the next updateTransform call. | ||
* Will get automatically set to true if a new child is added, or if a child's zIndex changes. | ||
* | ||
* @member {boolean} | ||
*/ | ||
this.sortDirty = false; | ||
} | ||
@@ -1036,3 +1189,3 @@ | ||
* | ||
* @private | ||
* @protected | ||
*/ | ||
@@ -1055,3 +1208,2 @@ Container.prototype.onChildrenChange = function onChildrenChange () | ||
var arguments$1 = arguments; | ||
var this$1 = this; | ||
@@ -1067,3 +1219,3 @@ var argumentsLength = arguments.length; | ||
{ | ||
this$1.addChild(arguments$1[i]); | ||
this.addChild(arguments$1[i]); | ||
} | ||
@@ -1080,2 +1232,4 @@ } | ||
child.parent = this; | ||
this.sortDirty = true; | ||
// ensure child transform will be recalculated | ||
@@ -1117,2 +1271,4 @@ child.transform._parentID = -1; | ||
child.parent = this; | ||
this.sortDirty = true; | ||
// ensure child transform will be recalculated | ||
@@ -1218,3 +1374,2 @@ child.transform._parentID = -1; | ||
var arguments$1 = arguments; | ||
var this$1 = this; | ||
@@ -1230,3 +1385,3 @@ var argumentsLength = arguments.length; | ||
{ | ||
this$1.removeChild(arguments$1[i]); | ||
this.removeChild(arguments$1[i]); | ||
} | ||
@@ -1290,3 +1445,2 @@ } | ||
{ | ||
var this$1 = this; | ||
if ( beginIndex === void 0 ) beginIndex = 0; | ||
@@ -1318,3 +1472,3 @@ | ||
{ | ||
removed[i$1].emit('removed', this$1); | ||
removed[i$1].emit('removed', this); | ||
} | ||
@@ -1333,2 +1487,29 @@ | ||
/** | ||
* Sorts children by zIndex. Previous order is mantained for 2 children with the same zIndex. | ||
*/ | ||
Container.prototype.sortChildren = function sortChildren$1 () | ||
{ | ||
var sortRequired = false; | ||
for (var i = 0, j = this.children.length; i < j; ++i) | ||
{ | ||
var child = this.children[i]; | ||
child._lastSortedIndex = i; | ||
if (!sortRequired && child.zIndex !== 0) | ||
{ | ||
sortRequired = true; | ||
} | ||
} | ||
if (sortRequired && this.children.length > 1) | ||
{ | ||
this.children.sort(sortChildren); | ||
} | ||
this.sortDirty = false; | ||
}; | ||
/** | ||
* Updates the transform on all children of this container for rendering | ||
@@ -1338,3 +1519,6 @@ */ | ||
{ | ||
var this$1 = this; | ||
if (this.sortableChildren && this.sortDirty) | ||
{ | ||
this.sortChildren(); | ||
} | ||
@@ -1350,3 +1534,3 @@ this._boundsID++; | ||
{ | ||
var child = this$1.children[i]; | ||
var child = this.children[i]; | ||
@@ -1366,4 +1550,2 @@ if (child.visible) | ||
{ | ||
var this$1 = this; | ||
this._bounds.clear(); | ||
@@ -1375,3 +1557,3 @@ | ||
{ | ||
var child = this$1.children[i]; | ||
var child = this.children[i]; | ||
@@ -1389,11 +1571,11 @@ if (!child.visible || !child.renderable) | ||
child._mask.calculateBounds(); | ||
this$1._bounds.addBoundsMask(child._bounds, child._mask._bounds); | ||
this._bounds.addBoundsMask(child._bounds, child._mask._bounds); | ||
} | ||
else if (child.filterArea) | ||
{ | ||
this$1._bounds.addBoundsArea(child._bounds, child.filterArea); | ||
this._bounds.addBoundsArea(child._bounds, child.filterArea); | ||
} | ||
else | ||
{ | ||
this$1._bounds.addBounds(child._bounds); | ||
this._bounds.addBounds(child._bounds); | ||
} | ||
@@ -1409,2 +1591,3 @@ } | ||
* | ||
* @protected | ||
*/ | ||
@@ -1423,4 +1606,2 @@ Container.prototype._calculateBounds = function _calculateBounds () | ||
{ | ||
var this$1 = this; | ||
// if the object is not visible or the alpha is 0 then no need to render this element | ||
@@ -1444,3 +1625,3 @@ if (!this.visible || this.worldAlpha <= 0 || !this.renderable) | ||
{ | ||
this$1.children[i].render(renderer); | ||
this.children[i].render(renderer); | ||
} | ||
@@ -1453,3 +1634,3 @@ } | ||
* | ||
* @private | ||
* @protected | ||
* @param {PIXI.Renderer} renderer - The renderer | ||
@@ -1459,4 +1640,2 @@ */ | ||
{ | ||
var this$1 = this; | ||
renderer.batch.flush(); | ||
@@ -1481,3 +1660,3 @@ | ||
{ | ||
this$1._enabledFilters.push(filters[i]); | ||
this._enabledFilters.push(filters[i]); | ||
} | ||
@@ -1503,3 +1682,3 @@ } | ||
{ | ||
this$1.children[i$1].render(renderer); | ||
this.children[i$1].render(renderer); | ||
} | ||
@@ -1523,3 +1702,3 @@ | ||
* | ||
* @private | ||
* @protected | ||
* @param {PIXI.Renderer} renderer - The renderer | ||
@@ -1549,2 +1728,4 @@ */ | ||
this.sortDirty = false; | ||
var destroyChildren = typeof options === 'boolean' ? options : options && options.children; | ||
@@ -1551,0 +1732,0 @@ |
{ | ||
"name": "@pixi/display", | ||
"version": "5.0.0-alpha.3", | ||
"version": "5.0.0-rc", | ||
"main": "lib/display.js", | ||
"module": "lib/display.es.js", | ||
"description": "PixiJS Application", | ||
"description": "Core display functionality", | ||
"author": "Mat Groves", | ||
@@ -28,4 +28,5 @@ "contributors": [ | ||
"dependencies": { | ||
"@pixi/math": "^5.0.0-alpha.3", | ||
"@pixi/utils": "^5.0.0-alpha.3", | ||
"@pixi/math": "^5.0.0-rc", | ||
"@pixi/settings": "^5.0.0-rc", | ||
"@pixi/utils": "^5.0.0-rc", | ||
"eventemitter3": "^2.0.0", | ||
@@ -35,4 +36,5 @@ "remove-array-items": "^1.0.0" | ||
"devDependencies": { | ||
"floss": "^2.1.3" | ||
} | ||
"floss": "^2.1.5" | ||
}, | ||
"gitHead": "9026a1bbca9a9d86b7a3b6d5eb4fa2c3145c2b85" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
259899
3007
5
+ Added@pixi/settings@^5.0.0-rc
Updated@pixi/math@^5.0.0-rc
Updated@pixi/utils@^5.0.0-rc