@pixi/sprite
Advanced tools
Comparing version 5.2.4 to 5.3.0
/*! | ||
* @pixi/sprite - v5.2.4 | ||
* Compiled Sun, 03 May 2020 22:38:52 UTC | ||
* @pixi/sprite - v5.3.0 | ||
* Compiled Thu, 18 Jun 2020 23:27:40 UTC | ||
* | ||
@@ -9,8 +9,198 @@ * @pixi/sprite is licensed under the MIT License. | ||
this.PIXI = this.PIXI || {}; | ||
var _pixi_sprite = (function (exports, math, utils, core, constants, display, settings) { | ||
var _pixi_sprite = (function (exports, constants, core, display, math, settings, utils) { | ||
'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
var arguments$1 = arguments; | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments$1[i]; | ||
for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p)) { t[p] = s[p]; } } | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
{ t[p] = s[p]; } } | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
{ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0) | ||
{ t[p[i]] = s[p[i]]; } } } | ||
return t; | ||
} | ||
function __decorate(decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") { r = Reflect.decorate(decorators, target, key, desc); } | ||
else { for (var i = decorators.length - 1; i >= 0; i--) { if (d = decorators[i]) { r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; } } } | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
} | ||
function __param(paramIndex, decorator) { | ||
return function (target, key) { decorator(target, key, paramIndex); } | ||
} | ||
function __metadata(metadataKey, metadataValue) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") { return Reflect.metadata(metadataKey, metadataValue); } | ||
} | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) { throw t[1]; } return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) { throw new TypeError("Generator is already executing."); } | ||
while (_) { try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) { return t; } | ||
if (y = 0, t) { op = [op[0] & 2, t.value]; } | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) { _.ops.pop(); } | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } } | ||
if (op[0] & 5) { throw op[1]; } return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
function __exportStar(m, exports) { | ||
for (var p in m) { if (!exports.hasOwnProperty(p)) { exports[p] = m[p]; } } | ||
} | ||
function __values(o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) { return m.call(o); } | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) { o = void 0; } | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
} | ||
function __read(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) { return o; } | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) { ar.push(r.value); } | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) { m.call(i); } | ||
} | ||
finally { if (e) { throw e.error; } } | ||
} | ||
return ar; | ||
} | ||
function __spread() { | ||
var arguments$1 = arguments; | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
{ ar = ar.concat(__read(arguments$1[i])); } | ||
return ar; | ||
} | ||
function __await(v) { | ||
return this instanceof __await ? (this.v = v, this) : new __await(v); | ||
} | ||
function __asyncGenerator(thisArg, _arguments, generator) { | ||
if (!Symbol.asyncIterator) { throw new TypeError("Symbol.asyncIterator is not defined."); } | ||
var g = generator.apply(thisArg, _arguments || []), i, q = []; | ||
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
function verb(n) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } } | ||
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } | ||
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } | ||
function fulfill(value) { resume("next", value); } | ||
function reject(value) { resume("throw", value); } | ||
function settle(f, v) { if (f(v), q.shift(), q.length) { resume(q[0][0], q[0][1]); } } | ||
} | ||
function __asyncDelegator(o) { | ||
var i, p; | ||
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; | ||
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } | ||
} | ||
function __asyncValues(o) { | ||
if (!Symbol.asyncIterator) { throw new TypeError("Symbol.asyncIterator is not defined."); } | ||
var m = o[Symbol.asyncIterator], i; | ||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
} | ||
function __makeTemplateObject(cooked, raw) { | ||
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } | ||
return cooked; | ||
}; | ||
function __importStar(mod) { | ||
if (mod && mod.__esModule) { return mod; } | ||
var result = {}; | ||
if (mod != null) { for (var k in mod) { if (Object.hasOwnProperty.call(mod, k)) { result[k] = mod[k]; } } } | ||
result.default = mod; | ||
return result; | ||
} | ||
function __importDefault(mod) { | ||
return (mod && mod.__esModule) ? mod : { default: mod }; | ||
} | ||
var tempPoint = new math.Point(); | ||
var indices = new Uint16Array([0, 1, 2, 0, 2, 3]); | ||
/** | ||
@@ -42,7 +232,9 @@ * The Sprite object is the base for all textured objects that are rendered to the screen | ||
*/ | ||
var Sprite = /*@__PURE__*/(function (Container) { | ||
function Sprite(texture) | ||
{ | ||
Container.call(this); | ||
var Sprite = /** @class */ (function (_super) { | ||
__extends(Sprite, _super); | ||
/** | ||
* @param {PIXI.Texture} [texture] - The texture for this sprite. | ||
*/ | ||
function Sprite(texture) { | ||
var _this = _super.call(this) || this; | ||
/** | ||
@@ -66,9 +258,3 @@ * The anchor point defines the normalized coordinates | ||
*/ | ||
this._anchor = new math.ObservablePoint( | ||
this._onAnchorUpdate, | ||
this, | ||
(texture ? texture.defaultAnchor.x : 0), | ||
(texture ? texture.defaultAnchor.y : 0) | ||
); | ||
_this._anchor = new math.ObservablePoint(_this._onAnchorUpdate, _this, (texture ? texture.defaultAnchor.x : 0), (texture ? texture.defaultAnchor.y : 0)); | ||
/** | ||
@@ -80,20 +266,17 @@ * The texture that the sprite is using | ||
*/ | ||
this._texture = null; | ||
_this._texture = null; | ||
/** | ||
* The width of the sprite (this is initially set by the texture) | ||
* | ||
* @private | ||
* @protected | ||
* @member {number} | ||
*/ | ||
this._width = 0; | ||
_this._width = 0; | ||
/** | ||
* The height of the sprite (this is initially set by the texture) | ||
* | ||
* @private | ||
* @protected | ||
* @member {number} | ||
*/ | ||
this._height = 0; | ||
_this._height = 0; | ||
/** | ||
@@ -106,7 +289,13 @@ * The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect. | ||
*/ | ||
this._tint = null; | ||
this._tintRGB = null; | ||
this.tint = 0xFFFFFF; | ||
_this._tint = null; | ||
/** | ||
* The tint applied to the sprite. This is a RGB value. A value of 0xFFFFFF will remove any tint effect. | ||
* | ||
* @private | ||
* @member {number} | ||
* @default 16777215 | ||
*/ | ||
_this._tintRGB = null; | ||
_this.tint = 0xFFFFFF; | ||
/** | ||
* The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. | ||
@@ -118,12 +307,4 @@ * | ||
*/ | ||
this.blendMode = constants.BLEND_MODES.NORMAL; | ||
_this.blendMode = constants.BLEND_MODES.NORMAL; | ||
/** | ||
* The shader that will be used to render the sprite. Set to null to remove a current shader. | ||
* | ||
* @member {PIXI.Filter|PIXI.Shader} | ||
*/ | ||
this.shader = null; | ||
/** | ||
* Cached tint value so we can tell when the tint is changed. | ||
@@ -136,4 +317,3 @@ * Value is used for 2d CanvasRenderer. | ||
*/ | ||
this._cachedTint = 0xFFFFFF; | ||
_this._cachedTint = 0xFFFFFF; | ||
/** | ||
@@ -146,7 +326,5 @@ * this is used to store the uvs data of the sprite, assigned at the same time | ||
*/ | ||
this.uvs = null; | ||
_this.uvs = null; | ||
// call texture setter | ||
this.texture = texture || core.Texture.EMPTY; | ||
_this.texture = texture || core.Texture.EMPTY; | ||
/** | ||
@@ -158,4 +336,3 @@ * this is used to store the vertex data of the sprite (basically a quad) | ||
*/ | ||
this.vertexData = new Float32Array(8); | ||
_this.vertexData = new Float32Array(8); | ||
/** | ||
@@ -167,14 +344,10 @@ * This is used to calculate the bounds of the object IF it is a trimmed sprite | ||
*/ | ||
this.vertexTrimmedData = null; | ||
this._transformID = -1; | ||
this._textureID = -1; | ||
this._transformTrimmedID = -1; | ||
this._textureTrimmedID = -1; | ||
_this.vertexTrimmedData = null; | ||
_this._transformID = -1; | ||
_this._textureID = -1; | ||
_this._transformTrimmedID = -1; | ||
_this._textureTrimmedID = -1; | ||
// Batchable stuff.. | ||
// TODO could make this a mixin? | ||
this.indices = indices; | ||
_this.indices = indices; | ||
/** | ||
@@ -187,4 +360,3 @@ * Plugin that is responsible for rendering this element. | ||
*/ | ||
this.pluginName = 'batch'; | ||
_this.pluginName = 'batch'; | ||
/** | ||
@@ -194,4 +366,3 @@ * used to fast check if a sprite is.. a sprite! | ||
*/ | ||
this.isSprite = true; | ||
_this.isSprite = true; | ||
/** | ||
@@ -203,34 +374,22 @@ * Internal roundPixels field | ||
*/ | ||
this._roundPixels = settings.settings.ROUND_PIXELS; | ||
_this._roundPixels = settings.settings.ROUND_PIXELS; | ||
return _this; | ||
} | ||
if ( Container ) Sprite.__proto__ = Container; | ||
Sprite.prototype = Object.create( Container && Container.prototype ); | ||
Sprite.prototype.constructor = Sprite; | ||
var prototypeAccessors = { roundPixels: { configurable: true },width: { configurable: true },height: { configurable: true },anchor: { configurable: true },tint: { configurable: true },texture: { configurable: true } }; | ||
/** | ||
* When the texture is updated, this event will fire to update the scale and frame | ||
* | ||
* @private | ||
* @protected | ||
*/ | ||
Sprite.prototype._onTextureUpdate = function _onTextureUpdate () | ||
{ | ||
Sprite.prototype._onTextureUpdate = function () { | ||
this._textureID = -1; | ||
this._textureTrimmedID = -1; | ||
this._cachedTint = 0xFFFFFF; | ||
// so if _width is 0 then width was not set.. | ||
if (this._width) | ||
{ | ||
if (this._width) { | ||
this.scale.x = utils.sign(this.scale.x) * this._width / this._texture.orig.width; | ||
} | ||
if (this._height) | ||
{ | ||
if (this._height) { | ||
this.scale.y = utils.sign(this.scale.y) * this._height / this._texture.orig.height; | ||
} | ||
}; | ||
/** | ||
@@ -241,31 +400,21 @@ * Called when the anchor position updates. | ||
*/ | ||
Sprite.prototype._onAnchorUpdate = function _onAnchorUpdate () | ||
{ | ||
Sprite.prototype._onAnchorUpdate = function () { | ||
this._transformID = -1; | ||
this._transformTrimmedID = -1; | ||
}; | ||
/** | ||
* calculates worldTransform * vertices, store it in vertexData | ||
*/ | ||
Sprite.prototype.calculateVertices = function calculateVertices () | ||
{ | ||
Sprite.prototype.calculateVertices = function () { | ||
var texture = this._texture; | ||
if (this._transformID === this.transform._worldID && this._textureID === texture._updateID) | ||
{ | ||
if (this._transformID === this.transform._worldID && this._textureID === texture._updateID) { | ||
return; | ||
} | ||
// update texture UV here, because base texture can be changed without calling `_onTextureUpdate` | ||
if (this._textureID !== texture._updateID) | ||
{ | ||
if (this._textureID !== texture._updateID) { | ||
this.uvs = this._texture._uvs.uvsFloat32; | ||
} | ||
this._transformID = this.transform._worldID; | ||
this._textureID = texture._updateID; | ||
// set the vertex data | ||
var wt = this.transform.worldTransform; | ||
@@ -282,3 +431,2 @@ var a = wt.a; | ||
var anchor = this._anchor; | ||
var w0 = 0; | ||
@@ -288,5 +436,3 @@ var w1 = 0; | ||
var h1 = 0; | ||
if (trim) | ||
{ | ||
if (trim) { | ||
// if the sprite is trimmed and is not a tilingsprite then we need to add the extra | ||
@@ -296,37 +442,26 @@ // space before transforming the sprite coords. | ||
w0 = w1 + trim.width; | ||
h1 = trim.y - (anchor._y * orig.height); | ||
h0 = h1 + trim.height; | ||
} | ||
else | ||
{ | ||
else { | ||
w1 = -anchor._x * orig.width; | ||
w0 = w1 + orig.width; | ||
h1 = -anchor._y * orig.height; | ||
h0 = h1 + orig.height; | ||
} | ||
// xy | ||
vertexData[0] = (a * w1) + (c * h1) + tx; | ||
vertexData[1] = (d * h1) + (b * w1) + ty; | ||
// xy | ||
vertexData[2] = (a * w0) + (c * h1) + tx; | ||
vertexData[3] = (d * h1) + (b * w0) + ty; | ||
// xy | ||
vertexData[4] = (a * w0) + (c * h0) + tx; | ||
vertexData[5] = (d * h0) + (b * w0) + ty; | ||
// xy | ||
vertexData[6] = (a * w1) + (c * h0) + tx; | ||
vertexData[7] = (d * h0) + (b * w1) + ty; | ||
if (this._roundPixels) | ||
{ | ||
if (this._roundPixels) { | ||
var resolution = settings.settings.RESOLUTION; | ||
for (var i = 0; i < vertexData.length; ++i) | ||
{ | ||
for (var i = 0; i < vertexData.length; ++i) { | ||
vertexData[i] = Math.round((vertexData[i] * resolution | 0) / resolution); | ||
@@ -336,3 +471,2 @@ } | ||
}; | ||
/** | ||
@@ -342,16 +476,11 @@ * calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData | ||
*/ | ||
Sprite.prototype.calculateTrimmedVertices = function calculateTrimmedVertices () | ||
{ | ||
if (!this.vertexTrimmedData) | ||
{ | ||
Sprite.prototype.calculateTrimmedVertices = function () { | ||
if (!this.vertexTrimmedData) { | ||
this.vertexTrimmedData = new Float32Array(8); | ||
} | ||
else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) | ||
{ | ||
else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) { | ||
return; | ||
} | ||
this._transformTrimmedID = this.transform._worldID; | ||
this._textureTrimmedID = this._texture._updateID; | ||
// lets do some special trim code! | ||
@@ -362,3 +491,2 @@ var texture = this._texture; | ||
var anchor = this._anchor; | ||
// lets calculate the new untrimmed bounds.. | ||
@@ -372,21 +500,15 @@ var wt = this.transform.worldTransform; | ||
var ty = wt.ty; | ||
var w1 = -anchor._x * orig.width; | ||
var w0 = w1 + orig.width; | ||
var h1 = -anchor._y * orig.height; | ||
var h0 = h1 + orig.height; | ||
// xy | ||
vertexData[0] = (a * w1) + (c * h1) + tx; | ||
vertexData[1] = (d * h1) + (b * w1) + ty; | ||
// xy | ||
vertexData[2] = (a * w0) + (c * h1) + tx; | ||
vertexData[3] = (d * h1) + (b * w0) + ty; | ||
// xy | ||
vertexData[4] = (a * w0) + (c * h0) + tx; | ||
vertexData[5] = (d * h0) + (b * w0) + ty; | ||
// xy | ||
@@ -396,3 +518,2 @@ vertexData[6] = (a * w1) + (c * h0) + tx; | ||
}; | ||
/** | ||
@@ -405,10 +526,7 @@ * | ||
*/ | ||
Sprite.prototype._render = function _render (renderer) | ||
{ | ||
Sprite.prototype._render = function (renderer) { | ||
this.calculateVertices(); | ||
renderer.batch.setObjectRenderer(renderer.plugins[this.pluginName]); | ||
renderer.plugins[this.pluginName].render(this); | ||
}; | ||
/** | ||
@@ -419,10 +537,7 @@ * Updates the bounds of the sprite. | ||
*/ | ||
Sprite.prototype._calculateBounds = function _calculateBounds () | ||
{ | ||
Sprite.prototype._calculateBounds = function () { | ||
var trim = this._texture.trim; | ||
var orig = this._texture.orig; | ||
// First lets check to see if the current texture has a trim.. | ||
if (!trim || (trim.width === orig.width && trim.height === orig.height)) | ||
{ | ||
if (!trim || (trim.width === orig.width && trim.height === orig.height)) { | ||
// no trim! lets use the usual calculations.. | ||
@@ -432,4 +547,3 @@ this.calculateVertices(); | ||
} | ||
else | ||
{ | ||
else { | ||
// lets calculate a special trimmed bounds... | ||
@@ -440,3 +554,2 @@ this.calculateTrimmedVertices(); | ||
}; | ||
/** | ||
@@ -448,7 +561,5 @@ * Gets the local bounds of the sprite object. | ||
*/ | ||
Sprite.prototype.getLocalBounds = function getLocalBounds (rect) | ||
{ | ||
Sprite.prototype.getLocalBounds = function (rect) { | ||
// we can do a fast local bounds if the sprite has no children! | ||
if (this.children.length === 0) | ||
{ | ||
if (this.children.length === 0) { | ||
this._bounds.minX = this._texture.orig.width * -this._anchor._x; | ||
@@ -458,29 +569,20 @@ this._bounds.minY = this._texture.orig.height * -this._anchor._y; | ||
this._bounds.maxY = this._texture.orig.height * (1 - this._anchor._y); | ||
if (!rect) | ||
{ | ||
if (!this._localBoundsRect) | ||
{ | ||
if (!rect) { | ||
if (!this._localBoundsRect) { | ||
this._localBoundsRect = new math.Rectangle(); | ||
} | ||
rect = this._localBoundsRect; | ||
} | ||
return this._bounds.getRectangle(rect); | ||
} | ||
return Container.prototype.getLocalBounds.call(this, rect); | ||
return _super.prototype.getLocalBounds.call(this, rect); | ||
}; | ||
/** | ||
* Tests if a point is inside this sprite | ||
* | ||
* @param {PIXI.Point} point - the point to test | ||
* @param {PIXI.IPointData} point - the point to test | ||
* @return {boolean} the result of the test | ||
*/ | ||
Sprite.prototype.containsPoint = function containsPoint (point) | ||
{ | ||
Sprite.prototype.containsPoint = function (point) { | ||
this.worldTransform.applyInverse(point, tempPoint); | ||
var width = this._texture.orig.width; | ||
@@ -490,16 +592,10 @@ var height = this._texture.orig.height; | ||
var y1 = 0; | ||
if (tempPoint.x >= x1 && tempPoint.x < x1 + width) | ||
{ | ||
if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { | ||
y1 = -height * this.anchor.y; | ||
if (tempPoint.y >= y1 && tempPoint.y < y1 + height) | ||
{ | ||
if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
/** | ||
@@ -515,25 +611,14 @@ * Destroys this sprite and optionally its texture and children | ||
*/ | ||
Sprite.prototype.destroy = function destroy (options) | ||
{ | ||
Container.prototype.destroy.call(this, options); | ||
Sprite.prototype.destroy = function (options) { | ||
_super.prototype.destroy.call(this, options); | ||
this._texture.off('update', this._onTextureUpdate, this); | ||
this._anchor = null; | ||
var destroyTexture = typeof options === 'boolean' ? options : options && options.texture; | ||
if (destroyTexture) | ||
{ | ||
if (destroyTexture) { | ||
var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture; | ||
this._texture.destroy(!!destroyBaseTexture); | ||
} | ||
this._texture = null; | ||
this.shader = null; | ||
}; | ||
// some helper functions.. | ||
/** | ||
@@ -544,164 +629,147 @@ * Helper function that creates a new sprite based on the source you provide. | ||
* @static | ||
* @param {string|PIXI.Texture|HTMLCanvasElement|HTMLVideoElement} source Source to create texture from | ||
* @param {object} [options] See {@link PIXI.BaseTexture}'s constructor for options. | ||
* @param {string|PIXI.Texture|HTMLCanvasElement|HTMLVideoElement} source - Source to create texture from | ||
* @param {object} [options] - See {@link PIXI.BaseTexture}'s constructor for options. | ||
* @return {PIXI.Sprite} The newly created sprite | ||
*/ | ||
Sprite.from = function from (source, options) | ||
{ | ||
Sprite.from = function (source, options) { | ||
var texture = (source instanceof core.Texture) | ||
? source | ||
: core.Texture.from(source, options); | ||
return new Sprite(texture); | ||
}; | ||
/** | ||
* If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation. | ||
* Advantages can include sharper image quality (like text) and faster rendering on canvas. | ||
* The main disadvantage is movement of objects may appear less smooth. | ||
* To set the global default, change {@link PIXI.settings.ROUND_PIXELS} | ||
* | ||
* @member {boolean} | ||
* @default false | ||
*/ | ||
prototypeAccessors.roundPixels.set = function (value) | ||
{ | ||
if (this._roundPixels !== value) | ||
{ | ||
this._transformID = -1; | ||
} | ||
this._roundPixels = value; | ||
}; | ||
prototypeAccessors.roundPixels.get = function () | ||
{ | ||
return this._roundPixels; | ||
}; | ||
/** | ||
* The width of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.width.get = function () | ||
{ | ||
return Math.abs(this.scale.x) * this._texture.orig.width; | ||
}; | ||
prototypeAccessors.width.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
var s = utils.sign(this.scale.x) || 1; | ||
this.scale.x = s * value / this._texture.orig.width; | ||
this._width = value; | ||
}; | ||
/** | ||
* The height of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.height.get = function () | ||
{ | ||
return Math.abs(this.scale.y) * this._texture.orig.height; | ||
}; | ||
prototypeAccessors.height.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
var s = utils.sign(this.scale.y) || 1; | ||
this.scale.y = s * value / this._texture.orig.height; | ||
this._height = value; | ||
}; | ||
/** | ||
* The anchor sets the origin point of the text. The default value is taken from the {@link PIXI.Texture|Texture} | ||
* and passed to the constructor. | ||
* | ||
* The default is `(0,0)`, this means the text's origin is the top left. | ||
* | ||
* Setting the anchor to `(0.5,0.5)` means the text's origin is centered. | ||
* | ||
* Setting the anchor to `(1,1)` would mean the text's origin point will be the bottom right corner. | ||
* | ||
* If you pass only single parameter, it will set both x and y to the same value as shown in the example below. | ||
* | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.anchor.set(0.5); // This will set the origin to center. (0.5) is same as (0.5, 0.5). | ||
* | ||
* @member {PIXI.ObservablePoint} | ||
*/ | ||
prototypeAccessors.anchor.get = function () | ||
{ | ||
return this._anchor; | ||
}; | ||
prototypeAccessors.anchor.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this._anchor.copyFrom(value); | ||
}; | ||
/** | ||
* The tint applied to the sprite. This is a hex value. | ||
* A value of 0xFFFFFF will remove any tint effect. | ||
* | ||
* @member {number} | ||
* @default 0xFFFFFF | ||
*/ | ||
prototypeAccessors.tint.get = function () | ||
{ | ||
return this._tint; | ||
}; | ||
prototypeAccessors.tint.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this._tint = value; | ||
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); | ||
}; | ||
/** | ||
* The texture that the sprite is using | ||
* | ||
* @member {PIXI.Texture} | ||
*/ | ||
prototypeAccessors.texture.get = function () | ||
{ | ||
return this._texture; | ||
}; | ||
prototypeAccessors.texture.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
if (this._texture === value) | ||
{ | ||
return; | ||
} | ||
if (this._texture) | ||
{ | ||
this._texture.off('update', this._onTextureUpdate, this); | ||
} | ||
this._texture = value || core.Texture.EMPTY; | ||
this._cachedTint = 0xFFFFFF; | ||
this._textureID = -1; | ||
this._textureTrimmedID = -1; | ||
if (value) | ||
{ | ||
// wait for the texture to load | ||
if (value.baseTexture.valid) | ||
{ | ||
this._onTextureUpdate(); | ||
Object.defineProperty(Sprite.prototype, "roundPixels", { | ||
get: function () { | ||
return this._roundPixels; | ||
}, | ||
/** | ||
* If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation. | ||
* Advantages can include sharper image quality (like text) and faster rendering on canvas. | ||
* The main disadvantage is movement of objects may appear less smooth. | ||
* To set the global default, change {@link PIXI.settings.ROUND_PIXELS} | ||
* | ||
* @member {boolean} | ||
* @default false | ||
*/ | ||
set: function (value) { | ||
if (this._roundPixels !== value) { | ||
this._transformID = -1; | ||
} | ||
else | ||
{ | ||
value.once('update', this._onTextureUpdate, this); | ||
this._roundPixels = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "width", { | ||
/** | ||
* The width of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
get: function () { | ||
return Math.abs(this.scale.x) * this._texture.orig.width; | ||
}, | ||
set: function (value) { | ||
var s = utils.sign(this.scale.x) || 1; | ||
this.scale.x = s * value / this._texture.orig.width; | ||
this._width = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "height", { | ||
/** | ||
* The height of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
get: function () { | ||
return Math.abs(this.scale.y) * this._texture.orig.height; | ||
}, | ||
set: function (value) { | ||
var s = utils.sign(this.scale.y) || 1; | ||
this.scale.y = s * value / this._texture.orig.height; | ||
this._height = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "anchor", { | ||
/** | ||
* The anchor sets the origin point of the text. The default value is taken from the {@link PIXI.Texture|Texture} | ||
* and passed to the constructor. | ||
* | ||
* The default is `(0,0)`, this means the text's origin is the top left. | ||
* | ||
* Setting the anchor to `(0.5,0.5)` means the text's origin is centered. | ||
* | ||
* Setting the anchor to `(1,1)` would mean the text's origin point will be the bottom right corner. | ||
* | ||
* If you pass only single parameter, it will set both x and y to the same value as shown in the example below. | ||
* | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.anchor.set(0.5); // This will set the origin to center. (0.5) is same as (0.5, 0.5). | ||
* | ||
* @member {PIXI.ObservablePoint} | ||
*/ | ||
get: function () { | ||
return this._anchor; | ||
}, | ||
set: function (value) { | ||
this._anchor.copyFrom(value); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "tint", { | ||
/** | ||
* The tint applied to the sprite. This is a hex value. | ||
* A value of 0xFFFFFF will remove any tint effect. | ||
* | ||
* @member {number} | ||
* @default 0xFFFFFF | ||
*/ | ||
get: function () { | ||
return this._tint; | ||
}, | ||
set: function (value) { | ||
this._tint = value; | ||
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "texture", { | ||
/** | ||
* The texture that the sprite is using | ||
* | ||
* @member {PIXI.Texture} | ||
*/ | ||
get: function () { | ||
return this._texture; | ||
}, | ||
set: function (value) { | ||
if (this._texture === value) { | ||
return; | ||
} | ||
} | ||
}; | ||
Object.defineProperties( Sprite.prototype, prototypeAccessors ); | ||
if (this._texture) { | ||
this._texture.off('update', this._onTextureUpdate, this); | ||
} | ||
this._texture = value || core.Texture.EMPTY; | ||
this._cachedTint = 0xFFFFFF; | ||
this._textureID = -1; | ||
this._textureTrimmedID = -1; | ||
if (value) { | ||
// wait for the texture to load | ||
if (value.baseTexture.valid) { | ||
this._onTextureUpdate(); | ||
} | ||
else { | ||
value.once('update', this._onTextureUpdate, this); | ||
} | ||
} | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return Sprite; | ||
@@ -714,4 +782,4 @@ }(display.Container)); | ||
}({}, PIXI, PIXI.utils, PIXI, PIXI, PIXI, PIXI)); | ||
}({}, PIXI, PIXI, PIXI, PIXI, PIXI, PIXI.utils)); | ||
Object.assign(this.PIXI, _pixi_sprite); | ||
//# sourceMappingURL=sprite.js.map |
/*! | ||
* @pixi/sprite - v5.2.4 | ||
* Compiled Sun, 03 May 2020 22:38:52 UTC | ||
* @pixi/sprite - v5.3.0 | ||
* Compiled Thu, 18 Jun 2020 23:27:40 UTC | ||
* | ||
@@ -8,3 +8,3 @@ * @pixi/sprite is licensed under the MIT License. | ||
*/ | ||
this.PIXI=this.PIXI||{};var _pixi_sprite=function(t,e,i,r,s,h,n){"use strict";var o=new e.Point,u=new Uint16Array([0,1,2,0,2,3]),a=function(t){function h(i){t.call(this),this._anchor=new e.ObservablePoint(this._onAnchorUpdate,this,i?i.defaultAnchor.x:0,i?i.defaultAnchor.y:0),this._texture=null,this._width=0,this._height=0,this._tint=null,this._tintRGB=null,this.tint=16777215,this.blendMode=s.BLEND_MODES.NORMAL,this.shader=null,this._cachedTint=16777215,this.uvs=null,this.texture=i||r.Texture.EMPTY,this.vertexData=new Float32Array(8),this.vertexTrimmedData=null,this._transformID=-1,this._textureID=-1,this._transformTrimmedID=-1,this._textureTrimmedID=-1,this.indices=u,this.pluginName="batch",this.isSprite=!0,this._roundPixels=n.settings.ROUND_PIXELS}t&&(h.__proto__=t),h.prototype=Object.create(t&&t.prototype),h.prototype.constructor=h;var a={roundPixels:{configurable:!0},width:{configurable:!0},height:{configurable:!0},anchor:{configurable:!0},tint:{configurable:!0},texture:{configurable:!0}};return h.prototype._onTextureUpdate=function(){this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this._width&&(this.scale.x=i.sign(this.scale.x)*this._width/this._texture.orig.width),this._height&&(this.scale.y=i.sign(this.scale.y)*this._height/this._texture.orig.height)},h.prototype._onAnchorUpdate=function(){this._transformID=-1,this._transformTrimmedID=-1},h.prototype.calculateVertices=function(){var t=this._texture;if(this._transformID!==this.transform._worldID||this._textureID!==t._updateID){this._textureID!==t._updateID&&(this.uvs=this._texture._uvs.uvsFloat32),this._transformID=this.transform._worldID,this._textureID=t._updateID;var e=this.transform.worldTransform,i=e.a,r=e.b,s=e.c,h=e.d,o=e.tx,u=e.ty,a=this.vertexData,_=t.trim,c=t.orig,d=this._anchor,l=0,x=0,f=0,g=0;if(_?(l=(x=_.x-d._x*c.width)+_.width,f=(g=_.y-d._y*c.height)+_.height):(l=(x=-d._x*c.width)+c.width,f=(g=-d._y*c.height)+c.height),a[0]=i*x+s*g+o,a[1]=h*g+r*x+u,a[2]=i*l+s*g+o,a[3]=h*g+r*l+u,a[4]=i*l+s*f+o,a[5]=h*f+r*l+u,a[6]=i*x+s*f+o,a[7]=h*f+r*x+u,this._roundPixels)for(var p=n.settings.RESOLUTION,m=0;m<a.length;++m)a[m]=Math.round((a[m]*p|0)/p)}},h.prototype.calculateTrimmedVertices=function(){if(this.vertexTrimmedData){if(this._transformTrimmedID===this.transform._worldID&&this._textureTrimmedID===this._texture._updateID)return}else this.vertexTrimmedData=new Float32Array(8);this._transformTrimmedID=this.transform._worldID,this._textureTrimmedID=this._texture._updateID;var t=this._texture,e=this.vertexTrimmedData,i=t.orig,r=this._anchor,s=this.transform.worldTransform,h=s.a,n=s.b,o=s.c,u=s.d,a=s.tx,_=s.ty,c=-r._x*i.width,d=c+i.width,l=-r._y*i.height,x=l+i.height;e[0]=h*c+o*l+a,e[1]=u*l+n*c+_,e[2]=h*d+o*l+a,e[3]=u*l+n*d+_,e[4]=h*d+o*x+a,e[5]=u*x+n*d+_,e[6]=h*c+o*x+a,e[7]=u*x+n*c+_},h.prototype._render=function(t){this.calculateVertices(),t.batch.setObjectRenderer(t.plugins[this.pluginName]),t.plugins[this.pluginName].render(this)},h.prototype._calculateBounds=function(){var t=this._texture.trim,e=this._texture.orig;!t||t.width===e.width&&t.height===e.height?(this.calculateVertices(),this._bounds.addQuad(this.vertexData)):(this.calculateTrimmedVertices(),this._bounds.addQuad(this.vertexTrimmedData))},h.prototype.getLocalBounds=function(i){return 0===this.children.length?(this._bounds.minX=this._texture.orig.width*-this._anchor._x,this._bounds.minY=this._texture.orig.height*-this._anchor._y,this._bounds.maxX=this._texture.orig.width*(1-this._anchor._x),this._bounds.maxY=this._texture.orig.height*(1-this._anchor._y),i||(this._localBoundsRect||(this._localBoundsRect=new e.Rectangle),i=this._localBoundsRect),this._bounds.getRectangle(i)):t.prototype.getLocalBounds.call(this,i)},h.prototype.containsPoint=function(t){this.worldTransform.applyInverse(t,o);var e=this._texture.orig.width,i=this._texture.orig.height,r=-e*this.anchor.x,s=0;return o.x>=r&&o.x<r+e&&(s=-i*this.anchor.y,o.y>=s&&o.y<s+i)},h.prototype.destroy=function(e){if(t.prototype.destroy.call(this,e),this._texture.off("update",this._onTextureUpdate,this),this._anchor=null,"boolean"==typeof e?e:e&&e.texture){var i="boolean"==typeof e?e:e&&e.baseTexture;this._texture.destroy(!!i)}this._texture=null,this.shader=null},h.from=function(t,e){return new h(t instanceof r.Texture?t:r.Texture.from(t,e))},a.roundPixels.set=function(t){this._roundPixels!==t&&(this._transformID=-1),this._roundPixels=t},a.roundPixels.get=function(){return this._roundPixels},a.width.get=function(){return Math.abs(this.scale.x)*this._texture.orig.width},a.width.set=function(t){var e=i.sign(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t},a.height.get=function(){return Math.abs(this.scale.y)*this._texture.orig.height},a.height.set=function(t){var e=i.sign(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t},a.anchor.get=function(){return this._anchor},a.anchor.set=function(t){this._anchor.copyFrom(t)},a.tint.get=function(){return this._tint},a.tint.set=function(t){this._tint=t,this._tintRGB=(t>>16)+(65280&t)+((255&t)<<16)},a.texture.get=function(){return this._texture},a.texture.set=function(t){this._texture!==t&&(this._texture&&this._texture.off("update",this._onTextureUpdate,this),this._texture=t||r.Texture.EMPTY,this._cachedTint=16777215,this._textureID=-1,this._textureTrimmedID=-1,t&&(t.baseTexture.valid?this._onTextureUpdate():t.once("update",this._onTextureUpdate,this)))},Object.defineProperties(h.prototype,a),h}(h.Container);return t.Sprite=a,t}({},PIXI,PIXI.utils,PIXI,PIXI,PIXI,PIXI);Object.assign(this.PIXI,_pixi_sprite); | ||
this.PIXI=this.PIXI||{};var _pixi_sprite=function(t,e,i,r,n,s,h){"use strict";var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)};var u=new n.Point,a=new Uint16Array([0,1,2,0,2,3]),_=function(t){function r(r){var h=t.call(this)||this;return h._anchor=new n.ObservablePoint(h._onAnchorUpdate,h,r?r.defaultAnchor.x:0,r?r.defaultAnchor.y:0),h._texture=null,h._width=0,h._height=0,h._tint=null,h._tintRGB=null,h.tint=16777215,h.blendMode=e.BLEND_MODES.NORMAL,h._cachedTint=16777215,h.uvs=null,h.texture=r||i.Texture.EMPTY,h.vertexData=new Float32Array(8),h.vertexTrimmedData=null,h._transformID=-1,h._textureID=-1,h._transformTrimmedID=-1,h._textureTrimmedID=-1,h.indices=a,h.pluginName="batch",h.isSprite=!0,h._roundPixels=s.settings.ROUND_PIXELS,h}return function(t,e){function i(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(r,t),r.prototype._onTextureUpdate=function(){this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this._width&&(this.scale.x=h.sign(this.scale.x)*this._width/this._texture.orig.width),this._height&&(this.scale.y=h.sign(this.scale.y)*this._height/this._texture.orig.height)},r.prototype._onAnchorUpdate=function(){this._transformID=-1,this._transformTrimmedID=-1},r.prototype.calculateVertices=function(){var t=this._texture;if(this._transformID!==this.transform._worldID||this._textureID!==t._updateID){this._textureID!==t._updateID&&(this.uvs=this._texture._uvs.uvsFloat32),this._transformID=this.transform._worldID,this._textureID=t._updateID;var e=this.transform.worldTransform,i=e.a,r=e.b,n=e.c,h=e.d,o=e.tx,u=e.ty,a=this.vertexData,_=t.trim,c=t.orig,d=this._anchor,l=0,x=0,p=0,f=0;if(_?(l=(x=_.x-d._x*c.width)+_.width,p=(f=_.y-d._y*c.height)+_.height):(l=(x=-d._x*c.width)+c.width,p=(f=-d._y*c.height)+c.height),a[0]=i*x+n*f+o,a[1]=h*f+r*x+u,a[2]=i*l+n*f+o,a[3]=h*f+r*l+u,a[4]=i*l+n*p+o,a[5]=h*p+r*l+u,a[6]=i*x+n*p+o,a[7]=h*p+r*x+u,this._roundPixels)for(var m=s.settings.RESOLUTION,g=0;g<a.length;++g)a[g]=Math.round((a[g]*m|0)/m)}},r.prototype.calculateTrimmedVertices=function(){if(this.vertexTrimmedData){if(this._transformTrimmedID===this.transform._worldID&&this._textureTrimmedID===this._texture._updateID)return}else this.vertexTrimmedData=new Float32Array(8);this._transformTrimmedID=this.transform._worldID,this._textureTrimmedID=this._texture._updateID;var t=this._texture,e=this.vertexTrimmedData,i=t.orig,r=this._anchor,n=this.transform.worldTransform,s=n.a,h=n.b,o=n.c,u=n.d,a=n.tx,_=n.ty,c=-r._x*i.width,d=c+i.width,l=-r._y*i.height,x=l+i.height;e[0]=s*c+o*l+a,e[1]=u*l+h*c+_,e[2]=s*d+o*l+a,e[3]=u*l+h*d+_,e[4]=s*d+o*x+a,e[5]=u*x+h*d+_,e[6]=s*c+o*x+a,e[7]=u*x+h*c+_},r.prototype._render=function(t){this.calculateVertices(),t.batch.setObjectRenderer(t.plugins[this.pluginName]),t.plugins[this.pluginName].render(this)},r.prototype._calculateBounds=function(){var t=this._texture.trim,e=this._texture.orig;!t||t.width===e.width&&t.height===e.height?(this.calculateVertices(),this._bounds.addQuad(this.vertexData)):(this.calculateTrimmedVertices(),this._bounds.addQuad(this.vertexTrimmedData))},r.prototype.getLocalBounds=function(e){return 0===this.children.length?(this._bounds.minX=this._texture.orig.width*-this._anchor._x,this._bounds.minY=this._texture.orig.height*-this._anchor._y,this._bounds.maxX=this._texture.orig.width*(1-this._anchor._x),this._bounds.maxY=this._texture.orig.height*(1-this._anchor._y),e||(this._localBoundsRect||(this._localBoundsRect=new n.Rectangle),e=this._localBoundsRect),this._bounds.getRectangle(e)):t.prototype.getLocalBounds.call(this,e)},r.prototype.containsPoint=function(t){this.worldTransform.applyInverse(t,u);var e=this._texture.orig.width,i=this._texture.orig.height,r=-e*this.anchor.x,n=0;return u.x>=r&&u.x<r+e&&(n=-i*this.anchor.y,u.y>=n&&u.y<n+i)},r.prototype.destroy=function(e){if(t.prototype.destroy.call(this,e),this._texture.off("update",this._onTextureUpdate,this),this._anchor=null,"boolean"==typeof e?e:e&&e.texture){var i="boolean"==typeof e?e:e&&e.baseTexture;this._texture.destroy(!!i)}this._texture=null},r.from=function(t,e){return new r(t instanceof i.Texture?t:i.Texture.from(t,e))},Object.defineProperty(r.prototype,"roundPixels",{get:function(){return this._roundPixels},set:function(t){this._roundPixels!==t&&(this._transformID=-1),this._roundPixels=t},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"width",{get:function(){return Math.abs(this.scale.x)*this._texture.orig.width},set:function(t){var e=h.sign(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"height",{get:function(){return Math.abs(this.scale.y)*this._texture.orig.height},set:function(t){var e=h.sign(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"anchor",{get:function(){return this._anchor},set:function(t){this._anchor.copyFrom(t)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"tint",{get:function(){return this._tint},set:function(t){this._tint=t,this._tintRGB=(t>>16)+(65280&t)+((255&t)<<16)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"texture",{get:function(){return this._texture},set:function(t){this._texture!==t&&(this._texture&&this._texture.off("update",this._onTextureUpdate,this),this._texture=t||i.Texture.EMPTY,this._cachedTint=16777215,this._textureID=-1,this._textureTrimmedID=-1,t&&(t.baseTexture.valid?this._onTextureUpdate():t.once("update",this._onTextureUpdate,this)))},enumerable:!1,configurable:!0}),r}(r.Container);return t.Sprite=_,t}({},PIXI,PIXI,PIXI,PIXI,PIXI,PIXI.utils);Object.assign(this.PIXI,_pixi_sprite); | ||
//# sourceMappingURL=sprite.min.js.map |
/*! | ||
* @pixi/sprite - v5.2.4 | ||
* Compiled Sun, 03 May 2020 22:38:52 UTC | ||
* @pixi/sprite - v5.3.0 | ||
* Compiled Thu, 18 Jun 2020 23:27:40 UTC | ||
* | ||
@@ -8,12 +8,40 @@ * @pixi/sprite is licensed under the MIT License. | ||
*/ | ||
import { Point, Rectangle, ObservablePoint } from '@pixi/math'; | ||
import { sign } from '@pixi/utils'; | ||
import { BLEND_MODES } from '@pixi/constants'; | ||
import { Texture } from '@pixi/core'; | ||
import { BLEND_MODES } from '@pixi/constants'; | ||
import { Container } from '@pixi/display'; | ||
import { Point, ObservablePoint, Rectangle } from '@pixi/math'; | ||
import { settings } from '@pixi/settings'; | ||
import { sign } from '@pixi/utils'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var tempPoint = new Point(); | ||
var indices = new Uint16Array([0, 1, 2, 0, 2, 3]); | ||
/** | ||
@@ -45,7 +73,9 @@ * The Sprite object is the base for all textured objects that are rendered to the screen | ||
*/ | ||
var Sprite = /*@__PURE__*/(function (Container) { | ||
function Sprite(texture) | ||
{ | ||
Container.call(this); | ||
var Sprite = /** @class */ (function (_super) { | ||
__extends(Sprite, _super); | ||
/** | ||
* @param {PIXI.Texture} [texture] - The texture for this sprite. | ||
*/ | ||
function Sprite(texture) { | ||
var _this = _super.call(this) || this; | ||
/** | ||
@@ -69,9 +99,3 @@ * The anchor point defines the normalized coordinates | ||
*/ | ||
this._anchor = new ObservablePoint( | ||
this._onAnchorUpdate, | ||
this, | ||
(texture ? texture.defaultAnchor.x : 0), | ||
(texture ? texture.defaultAnchor.y : 0) | ||
); | ||
_this._anchor = new ObservablePoint(_this._onAnchorUpdate, _this, (texture ? texture.defaultAnchor.x : 0), (texture ? texture.defaultAnchor.y : 0)); | ||
/** | ||
@@ -83,20 +107,17 @@ * The texture that the sprite is using | ||
*/ | ||
this._texture = null; | ||
_this._texture = null; | ||
/** | ||
* The width of the sprite (this is initially set by the texture) | ||
* | ||
* @private | ||
* @protected | ||
* @member {number} | ||
*/ | ||
this._width = 0; | ||
_this._width = 0; | ||
/** | ||
* The height of the sprite (this is initially set by the texture) | ||
* | ||
* @private | ||
* @protected | ||
* @member {number} | ||
*/ | ||
this._height = 0; | ||
_this._height = 0; | ||
/** | ||
@@ -109,7 +130,13 @@ * The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect. | ||
*/ | ||
this._tint = null; | ||
this._tintRGB = null; | ||
this.tint = 0xFFFFFF; | ||
_this._tint = null; | ||
/** | ||
* The tint applied to the sprite. This is a RGB value. A value of 0xFFFFFF will remove any tint effect. | ||
* | ||
* @private | ||
* @member {number} | ||
* @default 16777215 | ||
*/ | ||
_this._tintRGB = null; | ||
_this.tint = 0xFFFFFF; | ||
/** | ||
* The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. | ||
@@ -121,12 +148,4 @@ * | ||
*/ | ||
this.blendMode = BLEND_MODES.NORMAL; | ||
_this.blendMode = BLEND_MODES.NORMAL; | ||
/** | ||
* The shader that will be used to render the sprite. Set to null to remove a current shader. | ||
* | ||
* @member {PIXI.Filter|PIXI.Shader} | ||
*/ | ||
this.shader = null; | ||
/** | ||
* Cached tint value so we can tell when the tint is changed. | ||
@@ -139,4 +158,3 @@ * Value is used for 2d CanvasRenderer. | ||
*/ | ||
this._cachedTint = 0xFFFFFF; | ||
_this._cachedTint = 0xFFFFFF; | ||
/** | ||
@@ -149,7 +167,5 @@ * this is used to store the uvs data of the sprite, assigned at the same time | ||
*/ | ||
this.uvs = null; | ||
_this.uvs = null; | ||
// call texture setter | ||
this.texture = texture || Texture.EMPTY; | ||
_this.texture = texture || Texture.EMPTY; | ||
/** | ||
@@ -161,4 +177,3 @@ * this is used to store the vertex data of the sprite (basically a quad) | ||
*/ | ||
this.vertexData = new Float32Array(8); | ||
_this.vertexData = new Float32Array(8); | ||
/** | ||
@@ -170,14 +185,10 @@ * This is used to calculate the bounds of the object IF it is a trimmed sprite | ||
*/ | ||
this.vertexTrimmedData = null; | ||
this._transformID = -1; | ||
this._textureID = -1; | ||
this._transformTrimmedID = -1; | ||
this._textureTrimmedID = -1; | ||
_this.vertexTrimmedData = null; | ||
_this._transformID = -1; | ||
_this._textureID = -1; | ||
_this._transformTrimmedID = -1; | ||
_this._textureTrimmedID = -1; | ||
// Batchable stuff.. | ||
// TODO could make this a mixin? | ||
this.indices = indices; | ||
_this.indices = indices; | ||
/** | ||
@@ -190,4 +201,3 @@ * Plugin that is responsible for rendering this element. | ||
*/ | ||
this.pluginName = 'batch'; | ||
_this.pluginName = 'batch'; | ||
/** | ||
@@ -197,4 +207,3 @@ * used to fast check if a sprite is.. a sprite! | ||
*/ | ||
this.isSprite = true; | ||
_this.isSprite = true; | ||
/** | ||
@@ -206,34 +215,22 @@ * Internal roundPixels field | ||
*/ | ||
this._roundPixels = settings.ROUND_PIXELS; | ||
_this._roundPixels = settings.ROUND_PIXELS; | ||
return _this; | ||
} | ||
if ( Container ) Sprite.__proto__ = Container; | ||
Sprite.prototype = Object.create( Container && Container.prototype ); | ||
Sprite.prototype.constructor = Sprite; | ||
var prototypeAccessors = { roundPixels: { configurable: true },width: { configurable: true },height: { configurable: true },anchor: { configurable: true },tint: { configurable: true },texture: { configurable: true } }; | ||
/** | ||
* When the texture is updated, this event will fire to update the scale and frame | ||
* | ||
* @private | ||
* @protected | ||
*/ | ||
Sprite.prototype._onTextureUpdate = function _onTextureUpdate () | ||
{ | ||
Sprite.prototype._onTextureUpdate = function () { | ||
this._textureID = -1; | ||
this._textureTrimmedID = -1; | ||
this._cachedTint = 0xFFFFFF; | ||
// so if _width is 0 then width was not set.. | ||
if (this._width) | ||
{ | ||
if (this._width) { | ||
this.scale.x = sign(this.scale.x) * this._width / this._texture.orig.width; | ||
} | ||
if (this._height) | ||
{ | ||
if (this._height) { | ||
this.scale.y = sign(this.scale.y) * this._height / this._texture.orig.height; | ||
} | ||
}; | ||
/** | ||
@@ -244,31 +241,21 @@ * Called when the anchor position updates. | ||
*/ | ||
Sprite.prototype._onAnchorUpdate = function _onAnchorUpdate () | ||
{ | ||
Sprite.prototype._onAnchorUpdate = function () { | ||
this._transformID = -1; | ||
this._transformTrimmedID = -1; | ||
}; | ||
/** | ||
* calculates worldTransform * vertices, store it in vertexData | ||
*/ | ||
Sprite.prototype.calculateVertices = function calculateVertices () | ||
{ | ||
Sprite.prototype.calculateVertices = function () { | ||
var texture = this._texture; | ||
if (this._transformID === this.transform._worldID && this._textureID === texture._updateID) | ||
{ | ||
if (this._transformID === this.transform._worldID && this._textureID === texture._updateID) { | ||
return; | ||
} | ||
// update texture UV here, because base texture can be changed without calling `_onTextureUpdate` | ||
if (this._textureID !== texture._updateID) | ||
{ | ||
if (this._textureID !== texture._updateID) { | ||
this.uvs = this._texture._uvs.uvsFloat32; | ||
} | ||
this._transformID = this.transform._worldID; | ||
this._textureID = texture._updateID; | ||
// set the vertex data | ||
var wt = this.transform.worldTransform; | ||
@@ -285,3 +272,2 @@ var a = wt.a; | ||
var anchor = this._anchor; | ||
var w0 = 0; | ||
@@ -291,5 +277,3 @@ var w1 = 0; | ||
var h1 = 0; | ||
if (trim) | ||
{ | ||
if (trim) { | ||
// if the sprite is trimmed and is not a tilingsprite then we need to add the extra | ||
@@ -299,37 +283,26 @@ // space before transforming the sprite coords. | ||
w0 = w1 + trim.width; | ||
h1 = trim.y - (anchor._y * orig.height); | ||
h0 = h1 + trim.height; | ||
} | ||
else | ||
{ | ||
else { | ||
w1 = -anchor._x * orig.width; | ||
w0 = w1 + orig.width; | ||
h1 = -anchor._y * orig.height; | ||
h0 = h1 + orig.height; | ||
} | ||
// xy | ||
vertexData[0] = (a * w1) + (c * h1) + tx; | ||
vertexData[1] = (d * h1) + (b * w1) + ty; | ||
// xy | ||
vertexData[2] = (a * w0) + (c * h1) + tx; | ||
vertexData[3] = (d * h1) + (b * w0) + ty; | ||
// xy | ||
vertexData[4] = (a * w0) + (c * h0) + tx; | ||
vertexData[5] = (d * h0) + (b * w0) + ty; | ||
// xy | ||
vertexData[6] = (a * w1) + (c * h0) + tx; | ||
vertexData[7] = (d * h0) + (b * w1) + ty; | ||
if (this._roundPixels) | ||
{ | ||
if (this._roundPixels) { | ||
var resolution = settings.RESOLUTION; | ||
for (var i = 0; i < vertexData.length; ++i) | ||
{ | ||
for (var i = 0; i < vertexData.length; ++i) { | ||
vertexData[i] = Math.round((vertexData[i] * resolution | 0) / resolution); | ||
@@ -339,3 +312,2 @@ } | ||
}; | ||
/** | ||
@@ -345,16 +317,11 @@ * calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData | ||
*/ | ||
Sprite.prototype.calculateTrimmedVertices = function calculateTrimmedVertices () | ||
{ | ||
if (!this.vertexTrimmedData) | ||
{ | ||
Sprite.prototype.calculateTrimmedVertices = function () { | ||
if (!this.vertexTrimmedData) { | ||
this.vertexTrimmedData = new Float32Array(8); | ||
} | ||
else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) | ||
{ | ||
else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) { | ||
return; | ||
} | ||
this._transformTrimmedID = this.transform._worldID; | ||
this._textureTrimmedID = this._texture._updateID; | ||
// lets do some special trim code! | ||
@@ -365,3 +332,2 @@ var texture = this._texture; | ||
var anchor = this._anchor; | ||
// lets calculate the new untrimmed bounds.. | ||
@@ -375,21 +341,15 @@ var wt = this.transform.worldTransform; | ||
var ty = wt.ty; | ||
var w1 = -anchor._x * orig.width; | ||
var w0 = w1 + orig.width; | ||
var h1 = -anchor._y * orig.height; | ||
var h0 = h1 + orig.height; | ||
// xy | ||
vertexData[0] = (a * w1) + (c * h1) + tx; | ||
vertexData[1] = (d * h1) + (b * w1) + ty; | ||
// xy | ||
vertexData[2] = (a * w0) + (c * h1) + tx; | ||
vertexData[3] = (d * h1) + (b * w0) + ty; | ||
// xy | ||
vertexData[4] = (a * w0) + (c * h0) + tx; | ||
vertexData[5] = (d * h0) + (b * w0) + ty; | ||
// xy | ||
@@ -399,3 +359,2 @@ vertexData[6] = (a * w1) + (c * h0) + tx; | ||
}; | ||
/** | ||
@@ -408,10 +367,7 @@ * | ||
*/ | ||
Sprite.prototype._render = function _render (renderer) | ||
{ | ||
Sprite.prototype._render = function (renderer) { | ||
this.calculateVertices(); | ||
renderer.batch.setObjectRenderer(renderer.plugins[this.pluginName]); | ||
renderer.plugins[this.pluginName].render(this); | ||
}; | ||
/** | ||
@@ -422,10 +378,7 @@ * Updates the bounds of the sprite. | ||
*/ | ||
Sprite.prototype._calculateBounds = function _calculateBounds () | ||
{ | ||
Sprite.prototype._calculateBounds = function () { | ||
var trim = this._texture.trim; | ||
var orig = this._texture.orig; | ||
// First lets check to see if the current texture has a trim.. | ||
if (!trim || (trim.width === orig.width && trim.height === orig.height)) | ||
{ | ||
if (!trim || (trim.width === orig.width && trim.height === orig.height)) { | ||
// no trim! lets use the usual calculations.. | ||
@@ -435,4 +388,3 @@ this.calculateVertices(); | ||
} | ||
else | ||
{ | ||
else { | ||
// lets calculate a special trimmed bounds... | ||
@@ -443,3 +395,2 @@ this.calculateTrimmedVertices(); | ||
}; | ||
/** | ||
@@ -451,7 +402,5 @@ * Gets the local bounds of the sprite object. | ||
*/ | ||
Sprite.prototype.getLocalBounds = function getLocalBounds (rect) | ||
{ | ||
Sprite.prototype.getLocalBounds = function (rect) { | ||
// we can do a fast local bounds if the sprite has no children! | ||
if (this.children.length === 0) | ||
{ | ||
if (this.children.length === 0) { | ||
this._bounds.minX = this._texture.orig.width * -this._anchor._x; | ||
@@ -461,29 +410,20 @@ this._bounds.minY = this._texture.orig.height * -this._anchor._y; | ||
this._bounds.maxY = this._texture.orig.height * (1 - this._anchor._y); | ||
if (!rect) | ||
{ | ||
if (!this._localBoundsRect) | ||
{ | ||
if (!rect) { | ||
if (!this._localBoundsRect) { | ||
this._localBoundsRect = new Rectangle(); | ||
} | ||
rect = this._localBoundsRect; | ||
} | ||
return this._bounds.getRectangle(rect); | ||
} | ||
return Container.prototype.getLocalBounds.call(this, rect); | ||
return _super.prototype.getLocalBounds.call(this, rect); | ||
}; | ||
/** | ||
* Tests if a point is inside this sprite | ||
* | ||
* @param {PIXI.Point} point - the point to test | ||
* @param {PIXI.IPointData} point - the point to test | ||
* @return {boolean} the result of the test | ||
*/ | ||
Sprite.prototype.containsPoint = function containsPoint (point) | ||
{ | ||
Sprite.prototype.containsPoint = function (point) { | ||
this.worldTransform.applyInverse(point, tempPoint); | ||
var width = this._texture.orig.width; | ||
@@ -493,16 +433,10 @@ var height = this._texture.orig.height; | ||
var y1 = 0; | ||
if (tempPoint.x >= x1 && tempPoint.x < x1 + width) | ||
{ | ||
if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { | ||
y1 = -height * this.anchor.y; | ||
if (tempPoint.y >= y1 && tempPoint.y < y1 + height) | ||
{ | ||
if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
/** | ||
@@ -518,25 +452,14 @@ * Destroys this sprite and optionally its texture and children | ||
*/ | ||
Sprite.prototype.destroy = function destroy (options) | ||
{ | ||
Container.prototype.destroy.call(this, options); | ||
Sprite.prototype.destroy = function (options) { | ||
_super.prototype.destroy.call(this, options); | ||
this._texture.off('update', this._onTextureUpdate, this); | ||
this._anchor = null; | ||
var destroyTexture = typeof options === 'boolean' ? options : options && options.texture; | ||
if (destroyTexture) | ||
{ | ||
if (destroyTexture) { | ||
var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture; | ||
this._texture.destroy(!!destroyBaseTexture); | ||
} | ||
this._texture = null; | ||
this.shader = null; | ||
}; | ||
// some helper functions.. | ||
/** | ||
@@ -547,164 +470,147 @@ * Helper function that creates a new sprite based on the source you provide. | ||
* @static | ||
* @param {string|PIXI.Texture|HTMLCanvasElement|HTMLVideoElement} source Source to create texture from | ||
* @param {object} [options] See {@link PIXI.BaseTexture}'s constructor for options. | ||
* @param {string|PIXI.Texture|HTMLCanvasElement|HTMLVideoElement} source - Source to create texture from | ||
* @param {object} [options] - See {@link PIXI.BaseTexture}'s constructor for options. | ||
* @return {PIXI.Sprite} The newly created sprite | ||
*/ | ||
Sprite.from = function from (source, options) | ||
{ | ||
Sprite.from = function (source, options) { | ||
var texture = (source instanceof Texture) | ||
? source | ||
: Texture.from(source, options); | ||
return new Sprite(texture); | ||
}; | ||
/** | ||
* If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation. | ||
* Advantages can include sharper image quality (like text) and faster rendering on canvas. | ||
* The main disadvantage is movement of objects may appear less smooth. | ||
* To set the global default, change {@link PIXI.settings.ROUND_PIXELS} | ||
* | ||
* @member {boolean} | ||
* @default false | ||
*/ | ||
prototypeAccessors.roundPixels.set = function (value) | ||
{ | ||
if (this._roundPixels !== value) | ||
{ | ||
this._transformID = -1; | ||
} | ||
this._roundPixels = value; | ||
}; | ||
prototypeAccessors.roundPixels.get = function () | ||
{ | ||
return this._roundPixels; | ||
}; | ||
/** | ||
* The width of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.width.get = function () | ||
{ | ||
return Math.abs(this.scale.x) * this._texture.orig.width; | ||
}; | ||
prototypeAccessors.width.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
var s = sign(this.scale.x) || 1; | ||
this.scale.x = s * value / this._texture.orig.width; | ||
this._width = value; | ||
}; | ||
/** | ||
* The height of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.height.get = function () | ||
{ | ||
return Math.abs(this.scale.y) * this._texture.orig.height; | ||
}; | ||
prototypeAccessors.height.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
var s = sign(this.scale.y) || 1; | ||
this.scale.y = s * value / this._texture.orig.height; | ||
this._height = value; | ||
}; | ||
/** | ||
* The anchor sets the origin point of the text. The default value is taken from the {@link PIXI.Texture|Texture} | ||
* and passed to the constructor. | ||
* | ||
* The default is `(0,0)`, this means the text's origin is the top left. | ||
* | ||
* Setting the anchor to `(0.5,0.5)` means the text's origin is centered. | ||
* | ||
* Setting the anchor to `(1,1)` would mean the text's origin point will be the bottom right corner. | ||
* | ||
* If you pass only single parameter, it will set both x and y to the same value as shown in the example below. | ||
* | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.anchor.set(0.5); // This will set the origin to center. (0.5) is same as (0.5, 0.5). | ||
* | ||
* @member {PIXI.ObservablePoint} | ||
*/ | ||
prototypeAccessors.anchor.get = function () | ||
{ | ||
return this._anchor; | ||
}; | ||
prototypeAccessors.anchor.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this._anchor.copyFrom(value); | ||
}; | ||
/** | ||
* The tint applied to the sprite. This is a hex value. | ||
* A value of 0xFFFFFF will remove any tint effect. | ||
* | ||
* @member {number} | ||
* @default 0xFFFFFF | ||
*/ | ||
prototypeAccessors.tint.get = function () | ||
{ | ||
return this._tint; | ||
}; | ||
prototypeAccessors.tint.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this._tint = value; | ||
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); | ||
}; | ||
/** | ||
* The texture that the sprite is using | ||
* | ||
* @member {PIXI.Texture} | ||
*/ | ||
prototypeAccessors.texture.get = function () | ||
{ | ||
return this._texture; | ||
}; | ||
prototypeAccessors.texture.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
if (this._texture === value) | ||
{ | ||
return; | ||
} | ||
if (this._texture) | ||
{ | ||
this._texture.off('update', this._onTextureUpdate, this); | ||
} | ||
this._texture = value || Texture.EMPTY; | ||
this._cachedTint = 0xFFFFFF; | ||
this._textureID = -1; | ||
this._textureTrimmedID = -1; | ||
if (value) | ||
{ | ||
// wait for the texture to load | ||
if (value.baseTexture.valid) | ||
{ | ||
this._onTextureUpdate(); | ||
Object.defineProperty(Sprite.prototype, "roundPixels", { | ||
get: function () { | ||
return this._roundPixels; | ||
}, | ||
/** | ||
* If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation. | ||
* Advantages can include sharper image quality (like text) and faster rendering on canvas. | ||
* The main disadvantage is movement of objects may appear less smooth. | ||
* To set the global default, change {@link PIXI.settings.ROUND_PIXELS} | ||
* | ||
* @member {boolean} | ||
* @default false | ||
*/ | ||
set: function (value) { | ||
if (this._roundPixels !== value) { | ||
this._transformID = -1; | ||
} | ||
else | ||
{ | ||
value.once('update', this._onTextureUpdate, this); | ||
this._roundPixels = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "width", { | ||
/** | ||
* The width of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
get: function () { | ||
return Math.abs(this.scale.x) * this._texture.orig.width; | ||
}, | ||
set: function (value) { | ||
var s = sign(this.scale.x) || 1; | ||
this.scale.x = s * value / this._texture.orig.width; | ||
this._width = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "height", { | ||
/** | ||
* The height of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
get: function () { | ||
return Math.abs(this.scale.y) * this._texture.orig.height; | ||
}, | ||
set: function (value) { | ||
var s = sign(this.scale.y) || 1; | ||
this.scale.y = s * value / this._texture.orig.height; | ||
this._height = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "anchor", { | ||
/** | ||
* The anchor sets the origin point of the text. The default value is taken from the {@link PIXI.Texture|Texture} | ||
* and passed to the constructor. | ||
* | ||
* The default is `(0,0)`, this means the text's origin is the top left. | ||
* | ||
* Setting the anchor to `(0.5,0.5)` means the text's origin is centered. | ||
* | ||
* Setting the anchor to `(1,1)` would mean the text's origin point will be the bottom right corner. | ||
* | ||
* If you pass only single parameter, it will set both x and y to the same value as shown in the example below. | ||
* | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.anchor.set(0.5); // This will set the origin to center. (0.5) is same as (0.5, 0.5). | ||
* | ||
* @member {PIXI.ObservablePoint} | ||
*/ | ||
get: function () { | ||
return this._anchor; | ||
}, | ||
set: function (value) { | ||
this._anchor.copyFrom(value); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "tint", { | ||
/** | ||
* The tint applied to the sprite. This is a hex value. | ||
* A value of 0xFFFFFF will remove any tint effect. | ||
* | ||
* @member {number} | ||
* @default 0xFFFFFF | ||
*/ | ||
get: function () { | ||
return this._tint; | ||
}, | ||
set: function (value) { | ||
this._tint = value; | ||
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "texture", { | ||
/** | ||
* The texture that the sprite is using | ||
* | ||
* @member {PIXI.Texture} | ||
*/ | ||
get: function () { | ||
return this._texture; | ||
}, | ||
set: function (value) { | ||
if (this._texture === value) { | ||
return; | ||
} | ||
} | ||
}; | ||
Object.defineProperties( Sprite.prototype, prototypeAccessors ); | ||
if (this._texture) { | ||
this._texture.off('update', this._onTextureUpdate, this); | ||
} | ||
this._texture = value || Texture.EMPTY; | ||
this._cachedTint = 0xFFFFFF; | ||
this._textureID = -1; | ||
this._textureTrimmedID = -1; | ||
if (value) { | ||
// wait for the texture to load | ||
if (value.baseTexture.valid) { | ||
this._onTextureUpdate(); | ||
} | ||
else { | ||
value.once('update', this._onTextureUpdate, this); | ||
} | ||
} | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return Sprite; | ||
@@ -711,0 +617,0 @@ }(Container)); |
/*! | ||
* @pixi/sprite - v5.2.4 | ||
* Compiled Sun, 03 May 2020 22:38:52 UTC | ||
* @pixi/sprite - v5.3.0 | ||
* Compiled Thu, 18 Jun 2020 23:27:40 UTC | ||
* | ||
@@ -12,12 +12,40 @@ * @pixi/sprite is licensed under the MIT License. | ||
var math = require('@pixi/math'); | ||
var utils = require('@pixi/utils'); | ||
var constants = require('@pixi/constants'); | ||
var core = require('@pixi/core'); | ||
var constants = require('@pixi/constants'); | ||
var display = require('@pixi/display'); | ||
var math = require('@pixi/math'); | ||
var settings = require('@pixi/settings'); | ||
var utils = require('@pixi/utils'); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var tempPoint = new math.Point(); | ||
var indices = new Uint16Array([0, 1, 2, 0, 2, 3]); | ||
/** | ||
@@ -49,7 +77,9 @@ * The Sprite object is the base for all textured objects that are rendered to the screen | ||
*/ | ||
var Sprite = /*@__PURE__*/(function (Container) { | ||
function Sprite(texture) | ||
{ | ||
Container.call(this); | ||
var Sprite = /** @class */ (function (_super) { | ||
__extends(Sprite, _super); | ||
/** | ||
* @param {PIXI.Texture} [texture] - The texture for this sprite. | ||
*/ | ||
function Sprite(texture) { | ||
var _this = _super.call(this) || this; | ||
/** | ||
@@ -73,9 +103,3 @@ * The anchor point defines the normalized coordinates | ||
*/ | ||
this._anchor = new math.ObservablePoint( | ||
this._onAnchorUpdate, | ||
this, | ||
(texture ? texture.defaultAnchor.x : 0), | ||
(texture ? texture.defaultAnchor.y : 0) | ||
); | ||
_this._anchor = new math.ObservablePoint(_this._onAnchorUpdate, _this, (texture ? texture.defaultAnchor.x : 0), (texture ? texture.defaultAnchor.y : 0)); | ||
/** | ||
@@ -87,20 +111,17 @@ * The texture that the sprite is using | ||
*/ | ||
this._texture = null; | ||
_this._texture = null; | ||
/** | ||
* The width of the sprite (this is initially set by the texture) | ||
* | ||
* @private | ||
* @protected | ||
* @member {number} | ||
*/ | ||
this._width = 0; | ||
_this._width = 0; | ||
/** | ||
* The height of the sprite (this is initially set by the texture) | ||
* | ||
* @private | ||
* @protected | ||
* @member {number} | ||
*/ | ||
this._height = 0; | ||
_this._height = 0; | ||
/** | ||
@@ -113,7 +134,13 @@ * The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect. | ||
*/ | ||
this._tint = null; | ||
this._tintRGB = null; | ||
this.tint = 0xFFFFFF; | ||
_this._tint = null; | ||
/** | ||
* The tint applied to the sprite. This is a RGB value. A value of 0xFFFFFF will remove any tint effect. | ||
* | ||
* @private | ||
* @member {number} | ||
* @default 16777215 | ||
*/ | ||
_this._tintRGB = null; | ||
_this.tint = 0xFFFFFF; | ||
/** | ||
* The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. | ||
@@ -125,12 +152,4 @@ * | ||
*/ | ||
this.blendMode = constants.BLEND_MODES.NORMAL; | ||
_this.blendMode = constants.BLEND_MODES.NORMAL; | ||
/** | ||
* The shader that will be used to render the sprite. Set to null to remove a current shader. | ||
* | ||
* @member {PIXI.Filter|PIXI.Shader} | ||
*/ | ||
this.shader = null; | ||
/** | ||
* Cached tint value so we can tell when the tint is changed. | ||
@@ -143,4 +162,3 @@ * Value is used for 2d CanvasRenderer. | ||
*/ | ||
this._cachedTint = 0xFFFFFF; | ||
_this._cachedTint = 0xFFFFFF; | ||
/** | ||
@@ -153,7 +171,5 @@ * this is used to store the uvs data of the sprite, assigned at the same time | ||
*/ | ||
this.uvs = null; | ||
_this.uvs = null; | ||
// call texture setter | ||
this.texture = texture || core.Texture.EMPTY; | ||
_this.texture = texture || core.Texture.EMPTY; | ||
/** | ||
@@ -165,4 +181,3 @@ * this is used to store the vertex data of the sprite (basically a quad) | ||
*/ | ||
this.vertexData = new Float32Array(8); | ||
_this.vertexData = new Float32Array(8); | ||
/** | ||
@@ -174,14 +189,10 @@ * This is used to calculate the bounds of the object IF it is a trimmed sprite | ||
*/ | ||
this.vertexTrimmedData = null; | ||
this._transformID = -1; | ||
this._textureID = -1; | ||
this._transformTrimmedID = -1; | ||
this._textureTrimmedID = -1; | ||
_this.vertexTrimmedData = null; | ||
_this._transformID = -1; | ||
_this._textureID = -1; | ||
_this._transformTrimmedID = -1; | ||
_this._textureTrimmedID = -1; | ||
// Batchable stuff.. | ||
// TODO could make this a mixin? | ||
this.indices = indices; | ||
_this.indices = indices; | ||
/** | ||
@@ -194,4 +205,3 @@ * Plugin that is responsible for rendering this element. | ||
*/ | ||
this.pluginName = 'batch'; | ||
_this.pluginName = 'batch'; | ||
/** | ||
@@ -201,4 +211,3 @@ * used to fast check if a sprite is.. a sprite! | ||
*/ | ||
this.isSprite = true; | ||
_this.isSprite = true; | ||
/** | ||
@@ -210,34 +219,22 @@ * Internal roundPixels field | ||
*/ | ||
this._roundPixels = settings.settings.ROUND_PIXELS; | ||
_this._roundPixels = settings.settings.ROUND_PIXELS; | ||
return _this; | ||
} | ||
if ( Container ) Sprite.__proto__ = Container; | ||
Sprite.prototype = Object.create( Container && Container.prototype ); | ||
Sprite.prototype.constructor = Sprite; | ||
var prototypeAccessors = { roundPixels: { configurable: true },width: { configurable: true },height: { configurable: true },anchor: { configurable: true },tint: { configurable: true },texture: { configurable: true } }; | ||
/** | ||
* When the texture is updated, this event will fire to update the scale and frame | ||
* | ||
* @private | ||
* @protected | ||
*/ | ||
Sprite.prototype._onTextureUpdate = function _onTextureUpdate () | ||
{ | ||
Sprite.prototype._onTextureUpdate = function () { | ||
this._textureID = -1; | ||
this._textureTrimmedID = -1; | ||
this._cachedTint = 0xFFFFFF; | ||
// so if _width is 0 then width was not set.. | ||
if (this._width) | ||
{ | ||
if (this._width) { | ||
this.scale.x = utils.sign(this.scale.x) * this._width / this._texture.orig.width; | ||
} | ||
if (this._height) | ||
{ | ||
if (this._height) { | ||
this.scale.y = utils.sign(this.scale.y) * this._height / this._texture.orig.height; | ||
} | ||
}; | ||
/** | ||
@@ -248,31 +245,21 @@ * Called when the anchor position updates. | ||
*/ | ||
Sprite.prototype._onAnchorUpdate = function _onAnchorUpdate () | ||
{ | ||
Sprite.prototype._onAnchorUpdate = function () { | ||
this._transformID = -1; | ||
this._transformTrimmedID = -1; | ||
}; | ||
/** | ||
* calculates worldTransform * vertices, store it in vertexData | ||
*/ | ||
Sprite.prototype.calculateVertices = function calculateVertices () | ||
{ | ||
Sprite.prototype.calculateVertices = function () { | ||
var texture = this._texture; | ||
if (this._transformID === this.transform._worldID && this._textureID === texture._updateID) | ||
{ | ||
if (this._transformID === this.transform._worldID && this._textureID === texture._updateID) { | ||
return; | ||
} | ||
// update texture UV here, because base texture can be changed without calling `_onTextureUpdate` | ||
if (this._textureID !== texture._updateID) | ||
{ | ||
if (this._textureID !== texture._updateID) { | ||
this.uvs = this._texture._uvs.uvsFloat32; | ||
} | ||
this._transformID = this.transform._worldID; | ||
this._textureID = texture._updateID; | ||
// set the vertex data | ||
var wt = this.transform.worldTransform; | ||
@@ -289,3 +276,2 @@ var a = wt.a; | ||
var anchor = this._anchor; | ||
var w0 = 0; | ||
@@ -295,5 +281,3 @@ var w1 = 0; | ||
var h1 = 0; | ||
if (trim) | ||
{ | ||
if (trim) { | ||
// if the sprite is trimmed and is not a tilingsprite then we need to add the extra | ||
@@ -303,37 +287,26 @@ // space before transforming the sprite coords. | ||
w0 = w1 + trim.width; | ||
h1 = trim.y - (anchor._y * orig.height); | ||
h0 = h1 + trim.height; | ||
} | ||
else | ||
{ | ||
else { | ||
w1 = -anchor._x * orig.width; | ||
w0 = w1 + orig.width; | ||
h1 = -anchor._y * orig.height; | ||
h0 = h1 + orig.height; | ||
} | ||
// xy | ||
vertexData[0] = (a * w1) + (c * h1) + tx; | ||
vertexData[1] = (d * h1) + (b * w1) + ty; | ||
// xy | ||
vertexData[2] = (a * w0) + (c * h1) + tx; | ||
vertexData[3] = (d * h1) + (b * w0) + ty; | ||
// xy | ||
vertexData[4] = (a * w0) + (c * h0) + tx; | ||
vertexData[5] = (d * h0) + (b * w0) + ty; | ||
// xy | ||
vertexData[6] = (a * w1) + (c * h0) + tx; | ||
vertexData[7] = (d * h0) + (b * w1) + ty; | ||
if (this._roundPixels) | ||
{ | ||
if (this._roundPixels) { | ||
var resolution = settings.settings.RESOLUTION; | ||
for (var i = 0; i < vertexData.length; ++i) | ||
{ | ||
for (var i = 0; i < vertexData.length; ++i) { | ||
vertexData[i] = Math.round((vertexData[i] * resolution | 0) / resolution); | ||
@@ -343,3 +316,2 @@ } | ||
}; | ||
/** | ||
@@ -349,16 +321,11 @@ * calculates worldTransform * vertices for a non texture with a trim. store it in vertexTrimmedData | ||
*/ | ||
Sprite.prototype.calculateTrimmedVertices = function calculateTrimmedVertices () | ||
{ | ||
if (!this.vertexTrimmedData) | ||
{ | ||
Sprite.prototype.calculateTrimmedVertices = function () { | ||
if (!this.vertexTrimmedData) { | ||
this.vertexTrimmedData = new Float32Array(8); | ||
} | ||
else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) | ||
{ | ||
else if (this._transformTrimmedID === this.transform._worldID && this._textureTrimmedID === this._texture._updateID) { | ||
return; | ||
} | ||
this._transformTrimmedID = this.transform._worldID; | ||
this._textureTrimmedID = this._texture._updateID; | ||
// lets do some special trim code! | ||
@@ -369,3 +336,2 @@ var texture = this._texture; | ||
var anchor = this._anchor; | ||
// lets calculate the new untrimmed bounds.. | ||
@@ -379,21 +345,15 @@ var wt = this.transform.worldTransform; | ||
var ty = wt.ty; | ||
var w1 = -anchor._x * orig.width; | ||
var w0 = w1 + orig.width; | ||
var h1 = -anchor._y * orig.height; | ||
var h0 = h1 + orig.height; | ||
// xy | ||
vertexData[0] = (a * w1) + (c * h1) + tx; | ||
vertexData[1] = (d * h1) + (b * w1) + ty; | ||
// xy | ||
vertexData[2] = (a * w0) + (c * h1) + tx; | ||
vertexData[3] = (d * h1) + (b * w0) + ty; | ||
// xy | ||
vertexData[4] = (a * w0) + (c * h0) + tx; | ||
vertexData[5] = (d * h0) + (b * w0) + ty; | ||
// xy | ||
@@ -403,3 +363,2 @@ vertexData[6] = (a * w1) + (c * h0) + tx; | ||
}; | ||
/** | ||
@@ -412,10 +371,7 @@ * | ||
*/ | ||
Sprite.prototype._render = function _render (renderer) | ||
{ | ||
Sprite.prototype._render = function (renderer) { | ||
this.calculateVertices(); | ||
renderer.batch.setObjectRenderer(renderer.plugins[this.pluginName]); | ||
renderer.plugins[this.pluginName].render(this); | ||
}; | ||
/** | ||
@@ -426,10 +382,7 @@ * Updates the bounds of the sprite. | ||
*/ | ||
Sprite.prototype._calculateBounds = function _calculateBounds () | ||
{ | ||
Sprite.prototype._calculateBounds = function () { | ||
var trim = this._texture.trim; | ||
var orig = this._texture.orig; | ||
// First lets check to see if the current texture has a trim.. | ||
if (!trim || (trim.width === orig.width && trim.height === orig.height)) | ||
{ | ||
if (!trim || (trim.width === orig.width && trim.height === orig.height)) { | ||
// no trim! lets use the usual calculations.. | ||
@@ -439,4 +392,3 @@ this.calculateVertices(); | ||
} | ||
else | ||
{ | ||
else { | ||
// lets calculate a special trimmed bounds... | ||
@@ -447,3 +399,2 @@ this.calculateTrimmedVertices(); | ||
}; | ||
/** | ||
@@ -455,7 +406,5 @@ * Gets the local bounds of the sprite object. | ||
*/ | ||
Sprite.prototype.getLocalBounds = function getLocalBounds (rect) | ||
{ | ||
Sprite.prototype.getLocalBounds = function (rect) { | ||
// we can do a fast local bounds if the sprite has no children! | ||
if (this.children.length === 0) | ||
{ | ||
if (this.children.length === 0) { | ||
this._bounds.minX = this._texture.orig.width * -this._anchor._x; | ||
@@ -465,29 +414,20 @@ this._bounds.minY = this._texture.orig.height * -this._anchor._y; | ||
this._bounds.maxY = this._texture.orig.height * (1 - this._anchor._y); | ||
if (!rect) | ||
{ | ||
if (!this._localBoundsRect) | ||
{ | ||
if (!rect) { | ||
if (!this._localBoundsRect) { | ||
this._localBoundsRect = new math.Rectangle(); | ||
} | ||
rect = this._localBoundsRect; | ||
} | ||
return this._bounds.getRectangle(rect); | ||
} | ||
return Container.prototype.getLocalBounds.call(this, rect); | ||
return _super.prototype.getLocalBounds.call(this, rect); | ||
}; | ||
/** | ||
* Tests if a point is inside this sprite | ||
* | ||
* @param {PIXI.Point} point - the point to test | ||
* @param {PIXI.IPointData} point - the point to test | ||
* @return {boolean} the result of the test | ||
*/ | ||
Sprite.prototype.containsPoint = function containsPoint (point) | ||
{ | ||
Sprite.prototype.containsPoint = function (point) { | ||
this.worldTransform.applyInverse(point, tempPoint); | ||
var width = this._texture.orig.width; | ||
@@ -497,16 +437,10 @@ var height = this._texture.orig.height; | ||
var y1 = 0; | ||
if (tempPoint.x >= x1 && tempPoint.x < x1 + width) | ||
{ | ||
if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { | ||
y1 = -height * this.anchor.y; | ||
if (tempPoint.y >= y1 && tempPoint.y < y1 + height) | ||
{ | ||
if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
/** | ||
@@ -522,25 +456,14 @@ * Destroys this sprite and optionally its texture and children | ||
*/ | ||
Sprite.prototype.destroy = function destroy (options) | ||
{ | ||
Container.prototype.destroy.call(this, options); | ||
Sprite.prototype.destroy = function (options) { | ||
_super.prototype.destroy.call(this, options); | ||
this._texture.off('update', this._onTextureUpdate, this); | ||
this._anchor = null; | ||
var destroyTexture = typeof options === 'boolean' ? options : options && options.texture; | ||
if (destroyTexture) | ||
{ | ||
if (destroyTexture) { | ||
var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture; | ||
this._texture.destroy(!!destroyBaseTexture); | ||
} | ||
this._texture = null; | ||
this.shader = null; | ||
}; | ||
// some helper functions.. | ||
/** | ||
@@ -551,164 +474,147 @@ * Helper function that creates a new sprite based on the source you provide. | ||
* @static | ||
* @param {string|PIXI.Texture|HTMLCanvasElement|HTMLVideoElement} source Source to create texture from | ||
* @param {object} [options] See {@link PIXI.BaseTexture}'s constructor for options. | ||
* @param {string|PIXI.Texture|HTMLCanvasElement|HTMLVideoElement} source - Source to create texture from | ||
* @param {object} [options] - See {@link PIXI.BaseTexture}'s constructor for options. | ||
* @return {PIXI.Sprite} The newly created sprite | ||
*/ | ||
Sprite.from = function from (source, options) | ||
{ | ||
Sprite.from = function (source, options) { | ||
var texture = (source instanceof core.Texture) | ||
? source | ||
: core.Texture.from(source, options); | ||
return new Sprite(texture); | ||
}; | ||
/** | ||
* If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation. | ||
* Advantages can include sharper image quality (like text) and faster rendering on canvas. | ||
* The main disadvantage is movement of objects may appear less smooth. | ||
* To set the global default, change {@link PIXI.settings.ROUND_PIXELS} | ||
* | ||
* @member {boolean} | ||
* @default false | ||
*/ | ||
prototypeAccessors.roundPixels.set = function (value) | ||
{ | ||
if (this._roundPixels !== value) | ||
{ | ||
this._transformID = -1; | ||
} | ||
this._roundPixels = value; | ||
}; | ||
prototypeAccessors.roundPixels.get = function () | ||
{ | ||
return this._roundPixels; | ||
}; | ||
/** | ||
* The width of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.width.get = function () | ||
{ | ||
return Math.abs(this.scale.x) * this._texture.orig.width; | ||
}; | ||
prototypeAccessors.width.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
var s = utils.sign(this.scale.x) || 1; | ||
this.scale.x = s * value / this._texture.orig.width; | ||
this._width = value; | ||
}; | ||
/** | ||
* The height of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
prototypeAccessors.height.get = function () | ||
{ | ||
return Math.abs(this.scale.y) * this._texture.orig.height; | ||
}; | ||
prototypeAccessors.height.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
var s = utils.sign(this.scale.y) || 1; | ||
this.scale.y = s * value / this._texture.orig.height; | ||
this._height = value; | ||
}; | ||
/** | ||
* The anchor sets the origin point of the text. The default value is taken from the {@link PIXI.Texture|Texture} | ||
* and passed to the constructor. | ||
* | ||
* The default is `(0,0)`, this means the text's origin is the top left. | ||
* | ||
* Setting the anchor to `(0.5,0.5)` means the text's origin is centered. | ||
* | ||
* Setting the anchor to `(1,1)` would mean the text's origin point will be the bottom right corner. | ||
* | ||
* If you pass only single parameter, it will set both x and y to the same value as shown in the example below. | ||
* | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.anchor.set(0.5); // This will set the origin to center. (0.5) is same as (0.5, 0.5). | ||
* | ||
* @member {PIXI.ObservablePoint} | ||
*/ | ||
prototypeAccessors.anchor.get = function () | ||
{ | ||
return this._anchor; | ||
}; | ||
prototypeAccessors.anchor.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this._anchor.copyFrom(value); | ||
}; | ||
/** | ||
* The tint applied to the sprite. This is a hex value. | ||
* A value of 0xFFFFFF will remove any tint effect. | ||
* | ||
* @member {number} | ||
* @default 0xFFFFFF | ||
*/ | ||
prototypeAccessors.tint.get = function () | ||
{ | ||
return this._tint; | ||
}; | ||
prototypeAccessors.tint.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
this._tint = value; | ||
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); | ||
}; | ||
/** | ||
* The texture that the sprite is using | ||
* | ||
* @member {PIXI.Texture} | ||
*/ | ||
prototypeAccessors.texture.get = function () | ||
{ | ||
return this._texture; | ||
}; | ||
prototypeAccessors.texture.set = function (value) // eslint-disable-line require-jsdoc | ||
{ | ||
if (this._texture === value) | ||
{ | ||
return; | ||
} | ||
if (this._texture) | ||
{ | ||
this._texture.off('update', this._onTextureUpdate, this); | ||
} | ||
this._texture = value || core.Texture.EMPTY; | ||
this._cachedTint = 0xFFFFFF; | ||
this._textureID = -1; | ||
this._textureTrimmedID = -1; | ||
if (value) | ||
{ | ||
// wait for the texture to load | ||
if (value.baseTexture.valid) | ||
{ | ||
this._onTextureUpdate(); | ||
Object.defineProperty(Sprite.prototype, "roundPixels", { | ||
get: function () { | ||
return this._roundPixels; | ||
}, | ||
/** | ||
* If true PixiJS will Math.floor() x/y values when rendering, stopping pixel interpolation. | ||
* Advantages can include sharper image quality (like text) and faster rendering on canvas. | ||
* The main disadvantage is movement of objects may appear less smooth. | ||
* To set the global default, change {@link PIXI.settings.ROUND_PIXELS} | ||
* | ||
* @member {boolean} | ||
* @default false | ||
*/ | ||
set: function (value) { | ||
if (this._roundPixels !== value) { | ||
this._transformID = -1; | ||
} | ||
else | ||
{ | ||
value.once('update', this._onTextureUpdate, this); | ||
this._roundPixels = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "width", { | ||
/** | ||
* The width of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
get: function () { | ||
return Math.abs(this.scale.x) * this._texture.orig.width; | ||
}, | ||
set: function (value) { | ||
var s = utils.sign(this.scale.x) || 1; | ||
this.scale.x = s * value / this._texture.orig.width; | ||
this._width = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "height", { | ||
/** | ||
* The height of the sprite, setting this will actually modify the scale to achieve the value set | ||
* | ||
* @member {number} | ||
*/ | ||
get: function () { | ||
return Math.abs(this.scale.y) * this._texture.orig.height; | ||
}, | ||
set: function (value) { | ||
var s = utils.sign(this.scale.y) || 1; | ||
this.scale.y = s * value / this._texture.orig.height; | ||
this._height = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "anchor", { | ||
/** | ||
* The anchor sets the origin point of the text. The default value is taken from the {@link PIXI.Texture|Texture} | ||
* and passed to the constructor. | ||
* | ||
* The default is `(0,0)`, this means the text's origin is the top left. | ||
* | ||
* Setting the anchor to `(0.5,0.5)` means the text's origin is centered. | ||
* | ||
* Setting the anchor to `(1,1)` would mean the text's origin point will be the bottom right corner. | ||
* | ||
* If you pass only single parameter, it will set both x and y to the same value as shown in the example below. | ||
* | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.anchor.set(0.5); // This will set the origin to center. (0.5) is same as (0.5, 0.5). | ||
* | ||
* @member {PIXI.ObservablePoint} | ||
*/ | ||
get: function () { | ||
return this._anchor; | ||
}, | ||
set: function (value) { | ||
this._anchor.copyFrom(value); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "tint", { | ||
/** | ||
* The tint applied to the sprite. This is a hex value. | ||
* A value of 0xFFFFFF will remove any tint effect. | ||
* | ||
* @member {number} | ||
* @default 0xFFFFFF | ||
*/ | ||
get: function () { | ||
return this._tint; | ||
}, | ||
set: function (value) { | ||
this._tint = value; | ||
this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Sprite.prototype, "texture", { | ||
/** | ||
* The texture that the sprite is using | ||
* | ||
* @member {PIXI.Texture} | ||
*/ | ||
get: function () { | ||
return this._texture; | ||
}, | ||
set: function (value) { | ||
if (this._texture === value) { | ||
return; | ||
} | ||
} | ||
}; | ||
Object.defineProperties( Sprite.prototype, prototypeAccessors ); | ||
if (this._texture) { | ||
this._texture.off('update', this._onTextureUpdate, this); | ||
} | ||
this._texture = value || core.Texture.EMPTY; | ||
this._cachedTint = 0xFFFFFF; | ||
this._textureID = -1; | ||
this._textureTrimmedID = -1; | ||
if (value) { | ||
// wait for the texture to load | ||
if (value.baseTexture.valid) { | ||
this._onTextureUpdate(); | ||
} | ||
else { | ||
value.once('update', this._onTextureUpdate, this); | ||
} | ||
} | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return Sprite; | ||
@@ -715,0 +621,0 @@ }(display.Container)); |
{ | ||
"name": "@pixi/sprite", | ||
"version": "5.2.4", | ||
"version": "5.3.0", | ||
"main": "lib/sprite.js", | ||
@@ -27,10 +27,10 @@ "module": "lib/sprite.es.js", | ||
"dependencies": { | ||
"@pixi/constants": "5.2.4", | ||
"@pixi/core": "5.2.4", | ||
"@pixi/display": "5.2.4", | ||
"@pixi/math": "5.2.4", | ||
"@pixi/settings": "5.2.4", | ||
"@pixi/utils": "5.2.4" | ||
"@pixi/constants": "5.3.0", | ||
"@pixi/core": "5.3.0", | ||
"@pixi/display": "5.3.0", | ||
"@pixi/math": "5.3.0", | ||
"@pixi/settings": "5.3.0", | ||
"@pixi/utils": "5.3.0" | ||
}, | ||
"gitHead": "71c6b3b2061af4a4f3a95a265d46e933b8befc2c" | ||
"gitHead": "a9b7b32a9c0aeb3d9c42ef04b2c2a39be1cd0880" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Mixed license
License(Experimental) Package contains multiple licenses.
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
259812
1921
1
+ Added@pixi/constants@5.3.0(transitive)
+ Added@pixi/core@5.3.0(transitive)
+ Added@pixi/display@5.3.0(transitive)
+ Added@pixi/math@5.3.0(transitive)
+ Added@pixi/runner@5.3.0(transitive)
+ Added@pixi/settings@5.3.0(transitive)
+ Added@pixi/ticker@5.3.0(transitive)
+ Added@pixi/utils@5.3.0(transitive)
- Removed@pixi/constants@5.2.4(transitive)
- Removed@pixi/core@5.2.4(transitive)
- Removed@pixi/display@5.2.4(transitive)
- Removed@pixi/math@5.2.4(transitive)
- Removed@pixi/runner@5.2.4(transitive)
- Removed@pixi/settings@5.2.4(transitive)
- Removed@pixi/ticker@5.2.4(transitive)
- Removed@pixi/utils@5.2.4(transitive)
Updated@pixi/constants@5.3.0
Updated@pixi/core@5.3.0
Updated@pixi/display@5.3.0
Updated@pixi/math@5.3.0
Updated@pixi/settings@5.3.0
Updated@pixi/utils@5.3.0