@vpmedia/phaser 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -3
- package/dist/phaser.cjs +1 -1
- package/dist/phaser.cjs.LICENSE.txt +1 -1
- package/dist/phaser.cjs.map +1 -1
- package/dist/phaser.js +1 -1
- package/dist/phaser.js.LICENSE.txt +1 -1
- package/dist/phaser.js.map +1 -1
- package/package.json +23 -17
- package/src/index.js +142 -0
- package/src/phaser/core/animation.js +355 -0
- package/src/phaser/core/animation_manager.js +238 -0
- package/src/phaser/core/animation_parser.js +133 -0
- package/src/phaser/core/array_set.js +107 -0
- package/src/phaser/core/cache.js +558 -0
- package/src/phaser/core/const.js +106 -0
- package/src/phaser/core/device.js +67 -0
- package/src/phaser/core/device_util.js +388 -0
- package/src/phaser/core/dom.js +207 -0
- package/src/phaser/core/event_manager.js +243 -0
- package/src/phaser/core/factory.js +74 -0
- package/src/phaser/core/frame.js +75 -0
- package/src/phaser/core/frame_data.js +84 -0
- package/src/phaser/core/frame_util.js +33 -0
- package/src/phaser/core/game.js +412 -0
- package/src/phaser/core/input.js +401 -0
- package/src/phaser/core/input_button.js +102 -0
- package/src/phaser/core/input_handler.js +687 -0
- package/src/phaser/core/input_mouse.js +289 -0
- package/src/phaser/core/input_mspointer.js +197 -0
- package/src/phaser/core/input_pointer.js +427 -0
- package/src/phaser/core/input_touch.js +157 -0
- package/src/phaser/core/loader.js +1057 -0
- package/src/phaser/core/loader_parser.js +109 -0
- package/src/phaser/core/raf.js +46 -0
- package/src/phaser/core/raf_fb.js +75 -0
- package/src/phaser/core/raf_to.js +34 -0
- package/src/phaser/core/scale_manager.js +806 -0
- package/src/phaser/core/scene.js +65 -0
- package/src/phaser/core/scene_manager.js +309 -0
- package/src/phaser/core/signal.js +175 -0
- package/src/phaser/core/signal_binding.js +69 -0
- package/src/phaser/core/sound.js +538 -0
- package/src/phaser/core/sound_manager.js +364 -0
- package/src/phaser/core/stage.js +108 -0
- package/src/phaser/core/time.js +203 -0
- package/src/phaser/core/timer.js +276 -0
- package/src/phaser/core/timer_event.js +21 -0
- package/src/phaser/core/tween.js +329 -0
- package/src/phaser/core/tween_data.js +258 -0
- package/src/phaser/core/tween_easing.js +341 -0
- package/src/phaser/core/tween_manager.js +185 -0
- package/src/phaser/core/world.js +18 -0
- package/src/phaser/display/bitmap_text.js +322 -0
- package/src/phaser/display/button.js +194 -0
- package/src/phaser/display/canvas/buffer.js +36 -0
- package/src/phaser/display/canvas/graphics.js +227 -0
- package/src/phaser/display/canvas/masker.js +39 -0
- package/src/phaser/display/canvas/pool.js +126 -0
- package/src/phaser/display/canvas/renderer.js +123 -0
- package/src/phaser/display/canvas/tinter.js +144 -0
- package/src/phaser/display/canvas/util.js +159 -0
- package/src/phaser/display/display_object.js +597 -0
- package/src/phaser/display/graphics.js +723 -0
- package/src/phaser/display/graphics_data.js +27 -0
- package/src/phaser/display/graphics_data_util.js +15 -0
- package/src/phaser/display/group.js +227 -0
- package/src/phaser/display/image.js +288 -0
- package/src/phaser/display/sprite_batch.js +15 -0
- package/src/phaser/display/sprite_util.js +250 -0
- package/src/phaser/display/text.js +1089 -0
- package/src/phaser/display/webgl/abstract_filter.js +25 -0
- package/src/phaser/display/webgl/base_texture.js +68 -0
- package/src/phaser/display/webgl/blend_manager.js +35 -0
- package/src/phaser/display/webgl/earcut.js +662 -0
- package/src/phaser/display/webgl/earcut_node.js +28 -0
- package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
- package/src/phaser/display/webgl/filter_manager.js +46 -0
- package/src/phaser/display/webgl/filter_texture.js +61 -0
- package/src/phaser/display/webgl/graphics.js +624 -0
- package/src/phaser/display/webgl/graphics_data.js +42 -0
- package/src/phaser/display/webgl/mask_manager.js +36 -0
- package/src/phaser/display/webgl/render_texture.js +81 -0
- package/src/phaser/display/webgl/renderer.js +234 -0
- package/src/phaser/display/webgl/shader/complex.js +74 -0
- package/src/phaser/display/webgl/shader/fast.js +97 -0
- package/src/phaser/display/webgl/shader/normal.js +225 -0
- package/src/phaser/display/webgl/shader/primitive.js +72 -0
- package/src/phaser/display/webgl/shader/strip.js +77 -0
- package/src/phaser/display/webgl/shader_manager.js +89 -0
- package/src/phaser/display/webgl/sprite_batch.js +320 -0
- package/src/phaser/display/webgl/stencil_manager.js +170 -0
- package/src/phaser/display/webgl/texture.js +117 -0
- package/src/phaser/display/webgl/texture_util.js +34 -0
- package/src/phaser/display/webgl/util.js +78 -0
- package/src/phaser/geom/circle.js +186 -0
- package/src/phaser/geom/ellipse.js +65 -0
- package/src/phaser/geom/line.js +190 -0
- package/src/phaser/geom/matrix.js +147 -0
- package/src/phaser/geom/point.js +164 -0
- package/src/phaser/geom/polygon.js +140 -0
- package/src/phaser/geom/rectangle.js +306 -0
- package/src/phaser/geom/rounded_rectangle.js +36 -0
- package/src/phaser/geom/util/circle.js +122 -0
- package/src/phaser/geom/util/ellipse.js +34 -0
- package/src/phaser/geom/util/line.js +135 -0
- package/src/phaser/geom/util/matrix.js +53 -0
- package/src/phaser/geom/util/point.js +296 -0
- package/src/phaser/geom/util/polygon.js +28 -0
- package/src/phaser/geom/util/rectangle.js +229 -0
- package/src/phaser/geom/util/rounded_rectangle.js +32 -0
- package/src/phaser/util/math.js +297 -0
- package/src/phaser/util/string.js +32 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
5
|
+
*/
|
|
6
|
+
import Point from '../geom/point';
|
|
7
|
+
import Rectangle from '../geom/rectangle';
|
|
8
|
+
import Matrix from '../geom/matrix';
|
|
9
|
+
import { getIdentityMatrix } from '../geom/util/matrix';
|
|
10
|
+
import { PI_2 } from '../util/math';
|
|
11
|
+
import { renderCanvas, renderWebGL } from './sprite_util';
|
|
12
|
+
|
|
13
|
+
export default class {
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
this.exists = true;
|
|
17
|
+
this.renderable = false;
|
|
18
|
+
this.visible = true;
|
|
19
|
+
this.position = new Point(0, 0);
|
|
20
|
+
this.scale = new Point(1, 1);
|
|
21
|
+
this.pivot = new Point(0, 0);
|
|
22
|
+
this.anchor = new Point(0, 0);
|
|
23
|
+
this.rotation = 0;
|
|
24
|
+
this.alpha = 1;
|
|
25
|
+
this.hitArea = null;
|
|
26
|
+
this.parent = null;
|
|
27
|
+
this.worldAlpha = 1;
|
|
28
|
+
this.worldTransform = new Matrix();
|
|
29
|
+
// this.worldPosition = new Point(0, 0);
|
|
30
|
+
this.worldScale = new Point(1, 1);
|
|
31
|
+
// this.worldRotation = 0;
|
|
32
|
+
this.filterArea = null;
|
|
33
|
+
this._sr = 0;
|
|
34
|
+
this._cr = 1;
|
|
35
|
+
this.cachedBounds = new Rectangle(0, 0, 0, 0);
|
|
36
|
+
this.currentBounds = null;
|
|
37
|
+
this._mask = null;
|
|
38
|
+
this.children = [];
|
|
39
|
+
this.ignoreChildInput = false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
destroy() {
|
|
43
|
+
if (this.children) {
|
|
44
|
+
let i = this.children.length;
|
|
45
|
+
while (i) {
|
|
46
|
+
i -= 1;
|
|
47
|
+
this.children[i].destroy();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this.children = null;
|
|
51
|
+
this.exists = false;
|
|
52
|
+
this.renderable = false;
|
|
53
|
+
this.visible = false;
|
|
54
|
+
// TODO: investigate how to clean up properly object references without breaking delayed tween cleanups.
|
|
55
|
+
/*
|
|
56
|
+
this.position = null;
|
|
57
|
+
this.scale = null;
|
|
58
|
+
this.pivot = null;
|
|
59
|
+
this.anchor = null;
|
|
60
|
+
*/
|
|
61
|
+
this.hitArea = null;
|
|
62
|
+
this.parent = null;
|
|
63
|
+
this.worldTransform = null;
|
|
64
|
+
// this.worldPosition = null;
|
|
65
|
+
this.worldScale = null;
|
|
66
|
+
this.filterArea = null;
|
|
67
|
+
this.cachedBounds = null;
|
|
68
|
+
this.currentBounds = null;
|
|
69
|
+
this._mask = null;
|
|
70
|
+
this.destroyCachedSprite();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
addChild(child) {
|
|
74
|
+
return this.addChildAt(child, this.children.length);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
addChildAt(child, index) {
|
|
78
|
+
if (index >= 0 && index <= this.children.length) {
|
|
79
|
+
if (child.parent) {
|
|
80
|
+
child.parent.removeChild(child);
|
|
81
|
+
}
|
|
82
|
+
child.parent = this;
|
|
83
|
+
this.children.splice(index, 0, child);
|
|
84
|
+
return child;
|
|
85
|
+
}
|
|
86
|
+
throw new Error(child + 'addChildAt: The index ' + index + ' supplied is out of bounds ' + this.children.length);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
swapChildren(child, child2) {
|
|
90
|
+
if (child === child2) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const index1 = this.getChildIndex(child);
|
|
94
|
+
const index2 = this.getChildIndex(child2);
|
|
95
|
+
if (index1 < 0 || index2 < 0) {
|
|
96
|
+
throw new Error('swapChildren: Both the supplied DisplayObjects must be a child of the caller.');
|
|
97
|
+
}
|
|
98
|
+
this.children[index1] = child2;
|
|
99
|
+
this.children[index2] = child;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
getChildIndex(child) {
|
|
103
|
+
const index = this.children.indexOf(child);
|
|
104
|
+
if (index === -1) {
|
|
105
|
+
throw new Error('The supplied DisplayObject must be a child of the caller');
|
|
106
|
+
}
|
|
107
|
+
return index;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
setChildIndex(child, index) {
|
|
111
|
+
if (index < 0 || index >= this.children.length) {
|
|
112
|
+
throw new Error('The supplied index is out of bounds');
|
|
113
|
+
}
|
|
114
|
+
const currentIndex = this.getChildIndex(child);
|
|
115
|
+
this.children.splice(currentIndex, 1); // remove from old position
|
|
116
|
+
this.children.splice(index, 0, child); // add at new position
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getChildAt(index) {
|
|
120
|
+
if (index < 0 || index >= this.children.length) {
|
|
121
|
+
throw new Error('getChildAt: Supplied index ' + index + ' does not exist in the child list, or the supplied DisplayObject must be a child of the caller');
|
|
122
|
+
}
|
|
123
|
+
return this.children[index];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
removeChild(child) {
|
|
127
|
+
const index = this.children.indexOf(child);
|
|
128
|
+
if (index === -1) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return this.removeChildAt(index);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
removeChildAt(index) {
|
|
135
|
+
const child = this.getChildAt(index);
|
|
136
|
+
if (child) {
|
|
137
|
+
child.parent = undefined;
|
|
138
|
+
this.children.splice(index, 1);
|
|
139
|
+
}
|
|
140
|
+
return child;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
removeChildren(beginIndex, endIndex) {
|
|
144
|
+
if (beginIndex === undefined) {
|
|
145
|
+
beginIndex = 0;
|
|
146
|
+
}
|
|
147
|
+
if (endIndex === undefined) {
|
|
148
|
+
endIndex = this.children.length;
|
|
149
|
+
}
|
|
150
|
+
const range = endIndex - beginIndex;
|
|
151
|
+
if (range > 0 && range <= endIndex) {
|
|
152
|
+
const removed = this.children.splice(beginIndex, range);
|
|
153
|
+
for (let i = 0; i < removed.length; i += 1) {
|
|
154
|
+
const child = removed[i];
|
|
155
|
+
child.parent = undefined;
|
|
156
|
+
}
|
|
157
|
+
return removed;
|
|
158
|
+
}
|
|
159
|
+
if (range === 0 && this.children.length === 0) {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
throw new Error('removeChildren: Range Error, numeric values are outside the acceptable range');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
updateTransform(parent) {
|
|
166
|
+
if (!parent && !this.parent) {
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
if (!this.game || !this.visible) {
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
let p = this.parent;
|
|
173
|
+
if (parent) {
|
|
174
|
+
p = parent;
|
|
175
|
+
} else if (!this.parent) {
|
|
176
|
+
p = this.game.world;
|
|
177
|
+
}
|
|
178
|
+
// create some matrix refs for easy access
|
|
179
|
+
const pt = p.worldTransform;
|
|
180
|
+
const wt = this.worldTransform;
|
|
181
|
+
// temporary matrix variables
|
|
182
|
+
let a;
|
|
183
|
+
let b;
|
|
184
|
+
let c;
|
|
185
|
+
let d;
|
|
186
|
+
let tx;
|
|
187
|
+
let ty;
|
|
188
|
+
// so if rotation is between 0 then we can simplify the multiplication process..
|
|
189
|
+
if (this.rotation % PI_2) {
|
|
190
|
+
// check to see if the rotation is the same as the previous render. This means we only need to use sin and cos when rotation actually changes
|
|
191
|
+
if (this.rotation !== this.rotationCache) {
|
|
192
|
+
this.rotationCache = this.rotation;
|
|
193
|
+
this._sr = Math.sin(this.rotation);
|
|
194
|
+
this._cr = Math.cos(this.rotation);
|
|
195
|
+
}
|
|
196
|
+
// get the matrix values of the displayobject based on its transform properties..
|
|
197
|
+
a = this._cr * this.scale.x;
|
|
198
|
+
b = this._sr * this.scale.x;
|
|
199
|
+
c = -this._sr * this.scale.y;
|
|
200
|
+
d = this._cr * this.scale.y;
|
|
201
|
+
tx = this.position.x;
|
|
202
|
+
ty = this.position.y;
|
|
203
|
+
// check for pivot.. not often used so geared towards that fact!
|
|
204
|
+
if (this.pivot.x || this.pivot.y) {
|
|
205
|
+
tx -= this.pivot.x * a + this.pivot.y * c;
|
|
206
|
+
ty -= this.pivot.x * b + this.pivot.y * d;
|
|
207
|
+
}
|
|
208
|
+
// concat the parent matrix with the objects transform.
|
|
209
|
+
wt.a = a * pt.a + b * pt.c;
|
|
210
|
+
wt.b = a * pt.b + b * pt.d;
|
|
211
|
+
wt.c = c * pt.a + d * pt.c;
|
|
212
|
+
wt.d = c * pt.b + d * pt.d;
|
|
213
|
+
wt.tx = tx * pt.a + ty * pt.c + pt.tx;
|
|
214
|
+
wt.ty = tx * pt.b + ty * pt.d + pt.ty;
|
|
215
|
+
} else {
|
|
216
|
+
// lets do the fast version as we know there is no rotation..
|
|
217
|
+
a = this.scale.x;
|
|
218
|
+
d = this.scale.y;
|
|
219
|
+
tx = this.position.x - this.pivot.x * a;
|
|
220
|
+
ty = this.position.y - this.pivot.y * d;
|
|
221
|
+
wt.a = a * pt.a;
|
|
222
|
+
wt.b = a * pt.b;
|
|
223
|
+
wt.c = d * pt.c;
|
|
224
|
+
wt.d = d * pt.d;
|
|
225
|
+
wt.tx = tx * pt.a + ty * pt.c + pt.tx;
|
|
226
|
+
wt.ty = tx * pt.b + ty * pt.d + pt.ty;
|
|
227
|
+
}
|
|
228
|
+
// Set the World values
|
|
229
|
+
this.worldAlpha = this.alpha * p.worldAlpha;
|
|
230
|
+
// this.worldPosition.set(wt.tx, wt.ty);
|
|
231
|
+
this.worldScale.set(this.scale.x * Math.sqrt(wt.a * wt.a + wt.c * wt.c), this.scale.y * Math.sqrt(wt.b * wt.b + wt.d * wt.d));
|
|
232
|
+
this.worldRotation = Math.atan2(-wt.c, wt.d);
|
|
233
|
+
// reset the bounds each time this is called!
|
|
234
|
+
this.currentBounds = null;
|
|
235
|
+
// Custom callback?
|
|
236
|
+
if (this.transformCallback) {
|
|
237
|
+
this.transformCallback.call(this.transformCallbackContext, wt, pt);
|
|
238
|
+
}
|
|
239
|
+
for (let i = 0; i < this.children.length; i += 1) {
|
|
240
|
+
this.children[i].updateTransform();
|
|
241
|
+
}
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
getBounds(targetCoordinateSpace) {
|
|
246
|
+
const isTargetCoordinateSpaceDisplayObject = (targetCoordinateSpace && targetCoordinateSpace.contains !== undefined);
|
|
247
|
+
let isTargetCoordinateSpaceThisOrParent = true;
|
|
248
|
+
if (!isTargetCoordinateSpaceDisplayObject) {
|
|
249
|
+
targetCoordinateSpace = this;
|
|
250
|
+
} else if (targetCoordinateSpace.contains !== undefined) {
|
|
251
|
+
isTargetCoordinateSpaceThisOrParent = targetCoordinateSpace.contains(this);
|
|
252
|
+
} else {
|
|
253
|
+
isTargetCoordinateSpaceThisOrParent = false;
|
|
254
|
+
}
|
|
255
|
+
let i;
|
|
256
|
+
let matrixCache;
|
|
257
|
+
if (isTargetCoordinateSpaceDisplayObject) {
|
|
258
|
+
matrixCache = targetCoordinateSpace.worldTransform;
|
|
259
|
+
targetCoordinateSpace.worldTransform = getIdentityMatrix();
|
|
260
|
+
for (i = 0; i < targetCoordinateSpace.children.length; i += 1) {
|
|
261
|
+
targetCoordinateSpace.children[i].updateTransform();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
let minX = Infinity;
|
|
265
|
+
let minY = Infinity;
|
|
266
|
+
let maxX = -Infinity;
|
|
267
|
+
let maxY = -Infinity;
|
|
268
|
+
let childBounds;
|
|
269
|
+
let childMaxX;
|
|
270
|
+
let childMaxY;
|
|
271
|
+
let childVisible = false;
|
|
272
|
+
for (i = 0; i < this.children.length; i += 1) {
|
|
273
|
+
const child = this.children[i];
|
|
274
|
+
if (child.visible) {
|
|
275
|
+
childVisible = true;
|
|
276
|
+
childBounds = this.children[i].getBounds();
|
|
277
|
+
/*
|
|
278
|
+
if (isNaN(childBounds.x) && this.children[i].type !== 7) {
|
|
279
|
+
console.log(this.children[i]);
|
|
280
|
+
}
|
|
281
|
+
*/
|
|
282
|
+
minX = (minX < childBounds.x) ? minX : childBounds.x;
|
|
283
|
+
minY = (minY < childBounds.y) ? minY : childBounds.y;
|
|
284
|
+
childMaxX = childBounds.width + childBounds.x;
|
|
285
|
+
childMaxY = childBounds.height + childBounds.y;
|
|
286
|
+
maxX = (maxX > childMaxX) ? maxX : childMaxX;
|
|
287
|
+
maxY = (maxY > childMaxY) ? maxY : childMaxY;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
let bounds = this.cachedBounds;
|
|
291
|
+
if (!childVisible) {
|
|
292
|
+
bounds = new Rectangle();
|
|
293
|
+
const w0 = bounds.x;
|
|
294
|
+
const w1 = bounds.width + bounds.x;
|
|
295
|
+
const h0 = bounds.y;
|
|
296
|
+
const h1 = bounds.height + bounds.y;
|
|
297
|
+
const worldTransform = this.worldTransform;
|
|
298
|
+
const a = worldTransform.a;
|
|
299
|
+
const b = worldTransform.b;
|
|
300
|
+
const c = worldTransform.c;
|
|
301
|
+
const d = worldTransform.d;
|
|
302
|
+
const tx = worldTransform.tx;
|
|
303
|
+
const ty = worldTransform.ty;
|
|
304
|
+
const x1 = a * w1 + c * h1 + tx;
|
|
305
|
+
const y1 = d * h1 + b * w1 + ty;
|
|
306
|
+
const x2 = a * w0 + c * h1 + tx;
|
|
307
|
+
const y2 = d * h1 + b * w0 + ty;
|
|
308
|
+
const x3 = a * w0 + c * h0 + tx;
|
|
309
|
+
const y3 = d * h0 + b * w0 + ty;
|
|
310
|
+
const x4 = a * w1 + c * h0 + tx;
|
|
311
|
+
const y4 = d * h0 + b * w1 + ty;
|
|
312
|
+
maxX = x1;
|
|
313
|
+
maxY = y1;
|
|
314
|
+
minX = x1;
|
|
315
|
+
minY = y1;
|
|
316
|
+
minX = x2 < minX ? x2 : minX;
|
|
317
|
+
minX = x3 < minX ? x3 : minX;
|
|
318
|
+
minX = x4 < minX ? x4 : minX;
|
|
319
|
+
minY = y2 < minY ? y2 : minY;
|
|
320
|
+
minY = y3 < minY ? y3 : minY;
|
|
321
|
+
minY = y4 < minY ? y4 : minY;
|
|
322
|
+
maxX = x2 > maxX ? x2 : maxX;
|
|
323
|
+
maxX = x3 > maxX ? x3 : maxX;
|
|
324
|
+
maxX = x4 > maxX ? x4 : maxX;
|
|
325
|
+
maxY = y2 > maxY ? y2 : maxY;
|
|
326
|
+
maxY = y3 > maxY ? y3 : maxY;
|
|
327
|
+
maxY = y4 > maxY ? y4 : maxY;
|
|
328
|
+
}
|
|
329
|
+
bounds.x = minX;
|
|
330
|
+
bounds.y = minY;
|
|
331
|
+
bounds.width = maxX - minX;
|
|
332
|
+
bounds.height = maxY - minY;
|
|
333
|
+
if (isTargetCoordinateSpaceDisplayObject) {
|
|
334
|
+
targetCoordinateSpace.worldTransform = matrixCache;
|
|
335
|
+
for (i = 0; i < targetCoordinateSpace.children.length; i += 1) {
|
|
336
|
+
targetCoordinateSpace.children[i].updateTransform();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (!isTargetCoordinateSpaceThisOrParent) {
|
|
340
|
+
const targetCoordinateSpaceBounds = targetCoordinateSpace.getBounds();
|
|
341
|
+
bounds.x -= targetCoordinateSpaceBounds.x;
|
|
342
|
+
bounds.y -= targetCoordinateSpaceBounds.y;
|
|
343
|
+
}
|
|
344
|
+
return bounds;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
getLocalBounds() {
|
|
348
|
+
return this.getBounds(this);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
contains(child) {
|
|
352
|
+
if (!child) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
if (child === this) {
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
return this.contains(child.parent);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
renderWebGL(renderSession) {
|
|
362
|
+
if (!this.visible || this.alpha <= 0) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
let i;
|
|
366
|
+
if (this._mask || this._filters) {
|
|
367
|
+
// push filter first as we need to ensure the stencil buffer is correct for any masking
|
|
368
|
+
if (this._filters) {
|
|
369
|
+
renderSession.spriteBatch.flush();
|
|
370
|
+
renderSession.filterManager.pushFilter(this._filterBlock);
|
|
371
|
+
}
|
|
372
|
+
if (this._mask) {
|
|
373
|
+
renderSession.spriteBatch.stop();
|
|
374
|
+
renderSession.maskManager.pushMask(this.mask, renderSession);
|
|
375
|
+
renderSession.spriteBatch.start();
|
|
376
|
+
}
|
|
377
|
+
for (i = 0; i < this.children.length; i += 1) {
|
|
378
|
+
this.children[i].renderWebGL(renderSession);
|
|
379
|
+
}
|
|
380
|
+
renderSession.spriteBatch.stop();
|
|
381
|
+
if (this._mask) renderSession.maskManager.popMask(this._mask, renderSession);
|
|
382
|
+
if (this._filters) renderSession.filterManager.popFilter();
|
|
383
|
+
renderSession.spriteBatch.start();
|
|
384
|
+
} else {
|
|
385
|
+
for (i = 0; i < this.children.length; i += 1) {
|
|
386
|
+
this.children[i].renderWebGL(renderSession);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
renderCanvas(renderSession) {
|
|
392
|
+
if (!this.visible || this.alpha <= 0) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (this._mask) {
|
|
396
|
+
renderSession.maskManager.pushMask(this._mask, renderSession);
|
|
397
|
+
}
|
|
398
|
+
for (let i = 0; i < this.children.length; i += 1) {
|
|
399
|
+
this.children[i].renderCanvas(renderSession);
|
|
400
|
+
}
|
|
401
|
+
if (this._mask) {
|
|
402
|
+
renderSession.maskManager.popMask(renderSession);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
preUpdate() {
|
|
407
|
+
// override
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
update() {
|
|
411
|
+
// override
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
postUpdate() {
|
|
415
|
+
// override
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
generateTexture() {
|
|
419
|
+
// TODO
|
|
420
|
+
console.warn('display_object.generateTexture() is not implemented');
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
toGlobal(position) {
|
|
424
|
+
this.updateTransform();
|
|
425
|
+
return this.worldTransform.apply(position);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
toLocal(position, from) {
|
|
429
|
+
if (from) {
|
|
430
|
+
position = from.toGlobal(position);
|
|
431
|
+
}
|
|
432
|
+
this.updateTransform();
|
|
433
|
+
return this.worldTransform.applyInverse(position);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
renderCachedSprite(renderSession) {
|
|
437
|
+
if (!this._cachedSprite) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
this._cachedSprite.worldAlpha = this.worldAlpha;
|
|
441
|
+
if (renderSession.gl) {
|
|
442
|
+
renderWebGL(this._cachedSprite, renderSession);
|
|
443
|
+
} else {
|
|
444
|
+
renderCanvas(this._cachedSprite, renderSession);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
generateCachedSprite() {
|
|
449
|
+
// TODO
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
destroyCachedSprite() {
|
|
453
|
+
if (!this._cachedSprite) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
this._cachedSprite.texture.destroy(true);
|
|
457
|
+
this._cachedSprite = null;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// GETTER SETTER
|
|
461
|
+
|
|
462
|
+
get width() {
|
|
463
|
+
return this.getLocalBounds().width * this.scale.x;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
set width(value) {
|
|
467
|
+
const width = this.getLocalBounds().width;
|
|
468
|
+
if (width !== 0) {
|
|
469
|
+
this.scale.x = value / width;
|
|
470
|
+
} else {
|
|
471
|
+
this.scale.x = 1;
|
|
472
|
+
}
|
|
473
|
+
this._width = value;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
get height() {
|
|
477
|
+
return this.getLocalBounds().height * this.scale.y;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
set height(value) {
|
|
481
|
+
const height = this.getLocalBounds().height;
|
|
482
|
+
if (height !== 0) {
|
|
483
|
+
this.scale.y = value / height;
|
|
484
|
+
} else {
|
|
485
|
+
this.scale.y = 1;
|
|
486
|
+
}
|
|
487
|
+
this._height = value;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
get x() {
|
|
491
|
+
return this.position.x;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
set x(value) {
|
|
495
|
+
this.position.x = value;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
get y() {
|
|
499
|
+
return this.position.y;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
set y(value) {
|
|
503
|
+
this.position.y = value;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
get worldVisible() {
|
|
507
|
+
if (!this.visible) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
let item = this.parent;
|
|
511
|
+
if (!item) {
|
|
512
|
+
return this.visible;
|
|
513
|
+
}
|
|
514
|
+
do {
|
|
515
|
+
if (!item.visible) {
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
item = item.parent;
|
|
519
|
+
} while (item);
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// MASK
|
|
524
|
+
|
|
525
|
+
get mask() {
|
|
526
|
+
return this._mask;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
set mask(value) {
|
|
530
|
+
if (this._mask) {
|
|
531
|
+
this._mask.isMask = false;
|
|
532
|
+
}
|
|
533
|
+
this._mask = value;
|
|
534
|
+
if (value) {
|
|
535
|
+
this._mask.isMask = true;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// BOUNDS
|
|
540
|
+
|
|
541
|
+
get offsetX() {
|
|
542
|
+
return this.anchor.x * this.width;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
get offsetY() {
|
|
546
|
+
return this.anchor.y * this.height;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
get centerX() {
|
|
550
|
+
return (this.x - this.offsetX) + (this.width * 0.5);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
set centerX(value) {
|
|
554
|
+
this.x = (value + this.offsetX) - (this.width * 0.5);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
get centerY() {
|
|
558
|
+
return (this.y - this.offsetY) + (this.height * 0.5);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
set centerY(value) {
|
|
562
|
+
this.y = (value + this.offsetY) - (this.height * 0.5);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
get left() {
|
|
566
|
+
return this.x - this.offsetX;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
set left(value) {
|
|
570
|
+
this.x = value + this.offsetX;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
get right() {
|
|
574
|
+
return (this.x + this.width) - this.offsetX;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
set right(value) {
|
|
578
|
+
this.x = value - (this.width) + this.offsetX;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
get top() {
|
|
582
|
+
return this.y - this.offsetY;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
set top(value) {
|
|
586
|
+
this.y = value + this.offsetY;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
get bottom() {
|
|
590
|
+
return (this.y + this.height) - this.offsetY;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
set bottom(value) {
|
|
594
|
+
this.y = value - (this.height) + this.offsetY;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
}
|