melonjs 10.2.0 → 10.3.0
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 +1 -1
- package/dist/melonjs.js +4435 -4283
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3348 -3833
- package/dist/melonjs.module.js +4025 -3920
- package/package.json +13 -14
- package/src/audio/audio.js +45 -45
- package/src/camera/camera2d.js +78 -101
- package/src/entity/draggable.js +21 -29
- package/src/entity/droptarget.js +24 -31
- package/src/entity/entity.js +34 -38
- package/src/game.js +8 -8
- package/src/{shapes → geometries}/ellipse.js +46 -46
- package/src/{shapes → geometries}/line.js +14 -14
- package/src/{shapes → geometries}/poly.js +103 -54
- package/src/{shapes → geometries}/rectangle.js +73 -120
- package/src/index.js +18 -19
- package/src/input/gamepad.js +20 -20
- package/src/input/input.js +3 -3
- package/src/input/keyboard.js +122 -124
- package/src/input/pointer.js +102 -62
- package/src/input/pointerevent.js +97 -42
- package/src/lang/deprecated.js +29 -18
- package/src/level/level.js +34 -26
- package/src/level/tiled/TMXGroup.js +12 -13
- package/src/level/tiled/TMXLayer.js +41 -42
- package/src/level/tiled/TMXObject.js +76 -70
- package/src/level/tiled/TMXTile.js +13 -15
- package/src/level/tiled/TMXTileMap.js +26 -25
- package/src/level/tiled/TMXTileset.js +14 -15
- package/src/level/tiled/TMXTilesetGroup.js +5 -6
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXRenderer.js +18 -19
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
- package/src/loader/loader.js +46 -40
- package/src/loader/loadingscreen.js +7 -7
- package/src/math/color.js +68 -88
- package/src/math/math.js +33 -33
- package/src/math/matrix2.js +70 -71
- package/src/math/matrix3.js +90 -91
- package/src/math/observable_vector2.js +91 -92
- package/src/math/observable_vector3.js +110 -106
- package/src/math/vector2.js +116 -104
- package/src/math/vector3.js +129 -110
- package/src/particles/emitter.js +116 -126
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +82 -83
- package/src/physics/bounds.js +64 -66
- package/src/physics/collision.js +21 -22
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +26 -25
- package/src/physics/sat.js +21 -21
- package/src/physics/world.js +23 -22
- package/src/plugin/plugin.js +12 -13
- package/src/renderable/GUI.js +20 -26
- package/src/renderable/collectable.js +6 -7
- package/src/renderable/colorlayer.js +11 -12
- package/src/renderable/container.js +98 -81
- package/src/renderable/imagelayer.js +33 -35
- package/src/renderable/nineslicesprite.js +15 -16
- package/src/renderable/renderable.js +112 -111
- package/src/renderable/sprite.js +71 -58
- package/src/renderable/trigger.js +17 -19
- package/src/state/stage.js +14 -15
- package/src/state/state.js +78 -78
- package/src/system/device.js +137 -180
- package/src/system/event.js +116 -104
- package/src/system/pooling.js +15 -15
- package/src/system/save.js +9 -6
- package/src/system/timer.js +33 -33
- package/src/text/bitmaptext.js +39 -46
- package/src/text/bitmaptextdata.js +14 -15
- package/src/text/text.js +55 -58
- package/src/tweens/easing.js +5 -5
- package/src/tweens/interpolation.js +5 -5
- package/src/tweens/tween.js +49 -40
- package/src/utils/agent.js +12 -11
- package/src/utils/array.js +8 -8
- package/src/utils/file.js +7 -7
- package/src/utils/function.js +8 -8
- package/src/utils/string.js +19 -19
- package/src/utils/utils.js +23 -23
- package/src/video/canvas/canvas_renderer.js +127 -128
- package/src/video/renderer.js +69 -69
- package/src/video/texture.js +80 -82
- package/src/video/texture_cache.js +2 -4
- package/src/video/video.js +38 -38
- package/src/video/webgl/buffer/vertex.js +11 -3
- package/src/video/webgl/glshader.js +31 -32
- package/src/video/webgl/webgl_compositor.js +145 -127
- package/src/video/webgl/webgl_renderer.js +196 -175
|
@@ -6,12 +6,11 @@ import {clamp} from "./math.js";
|
|
|
6
6
|
* @classdesc
|
|
7
7
|
* A Vector2d object that provide notification by executing the given callback when the vector is changed.
|
|
8
8
|
* @class ObservableVector2d
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {Object} settings additional required parameters
|
|
9
|
+
* @augments me.Vector2d
|
|
10
|
+
* @memberof me
|
|
11
|
+
* @param {number} [x=0] x value of the vector
|
|
12
|
+
* @param {number} [y=0] y value of the vector
|
|
13
|
+
* @param {object} settings additional required parameters
|
|
15
14
|
* @param {Function} settings.onUpdate the callback to be executed when the vector is changed
|
|
16
15
|
* @param {Function} [settings.scope] the value to use as this when calling onUpdate
|
|
17
16
|
*/
|
|
@@ -42,21 +41,15 @@ class ObservableVector2d extends Vector2d {
|
|
|
42
41
|
/**
|
|
43
42
|
* x value of the vector
|
|
44
43
|
* @public
|
|
45
|
-
* @type
|
|
44
|
+
* @type {number}
|
|
46
45
|
* @name x
|
|
47
|
-
* @
|
|
46
|
+
* @memberof me.ObservableVector2d
|
|
48
47
|
*/
|
|
49
48
|
|
|
50
|
-
/**
|
|
51
|
-
* @ignore
|
|
52
|
-
*/
|
|
53
49
|
get x() {
|
|
54
50
|
return this._x;
|
|
55
51
|
}
|
|
56
52
|
|
|
57
|
-
/**
|
|
58
|
-
* @ignore
|
|
59
|
-
*/
|
|
60
53
|
set x(value) {
|
|
61
54
|
var ret = this.onUpdate.call(this.scope, value, this._y, this._x, this._y);
|
|
62
55
|
if (ret && "x" in ret) {
|
|
@@ -70,21 +63,15 @@ class ObservableVector2d extends Vector2d {
|
|
|
70
63
|
/**
|
|
71
64
|
* y value of the vector
|
|
72
65
|
* @public
|
|
73
|
-
* @type
|
|
66
|
+
* @type {number}
|
|
74
67
|
* @name y
|
|
75
|
-
* @
|
|
68
|
+
* @memberof me.ObservableVector2d
|
|
76
69
|
*/
|
|
77
70
|
|
|
78
|
-
/**
|
|
79
|
-
* @ignore
|
|
80
|
-
*/
|
|
81
71
|
get y() {
|
|
82
72
|
return this._y;
|
|
83
73
|
}
|
|
84
74
|
|
|
85
|
-
/**
|
|
86
|
-
* @ignore
|
|
87
|
-
*/
|
|
88
75
|
set y(value) {
|
|
89
76
|
var ret = this.onUpdate.call(this.scope, this._x, value, this._x, this._y);
|
|
90
77
|
if (ret && "y" in ret) {
|
|
@@ -110,11 +97,11 @@ class ObservableVector2d extends Vector2d {
|
|
|
110
97
|
/**
|
|
111
98
|
* set the vector value without triggering the callback
|
|
112
99
|
* @name setMuted
|
|
113
|
-
* @
|
|
100
|
+
* @memberof me.ObservableVector2d
|
|
114
101
|
* @function
|
|
115
|
-
* @param {
|
|
116
|
-
* @param {
|
|
117
|
-
* @
|
|
102
|
+
* @param {number} x x value of the vector
|
|
103
|
+
* @param {number} y y value of the vector
|
|
104
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
118
105
|
*/
|
|
119
106
|
setMuted(x, y) {
|
|
120
107
|
this._x = x;
|
|
@@ -125,11 +112,11 @@ class ObservableVector2d extends Vector2d {
|
|
|
125
112
|
/**
|
|
126
113
|
* set the callback to be executed when the vector is changed
|
|
127
114
|
* @name setCallback
|
|
128
|
-
* @
|
|
115
|
+
* @memberof me.ObservableVector2d
|
|
129
116
|
* @function
|
|
130
|
-
* @param {
|
|
131
|
-
* @param {
|
|
132
|
-
* @
|
|
117
|
+
* @param {Function} fn callback
|
|
118
|
+
* @param {Function} [scope=null] scope
|
|
119
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
133
120
|
*/
|
|
134
121
|
setCallback(fn, scope = null) {
|
|
135
122
|
if (typeof(fn) !== "function") {
|
|
@@ -145,10 +132,10 @@ class ObservableVector2d extends Vector2d {
|
|
|
145
132
|
/**
|
|
146
133
|
* Add the passed vector to this vector
|
|
147
134
|
* @name add
|
|
148
|
-
* @
|
|
135
|
+
* @memberof me.ObservableVector2d
|
|
149
136
|
* @function
|
|
150
137
|
* @param {me.ObservableVector2d} v
|
|
151
|
-
* @
|
|
138
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
152
139
|
*/
|
|
153
140
|
add(v) {
|
|
154
141
|
return this._set(this._x + v.x, this._y + v.y);
|
|
@@ -157,10 +144,10 @@ class ObservableVector2d extends Vector2d {
|
|
|
157
144
|
/**
|
|
158
145
|
* Substract the passed vector to this vector
|
|
159
146
|
* @name sub
|
|
160
|
-
* @
|
|
147
|
+
* @memberof me.ObservableVector2d
|
|
161
148
|
* @function
|
|
162
149
|
* @param {me.ObservableVector2d} v
|
|
163
|
-
* @
|
|
150
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
164
151
|
*/
|
|
165
152
|
sub(v) {
|
|
166
153
|
return this._set(this._x - v.x, this._y - v.y);
|
|
@@ -169,11 +156,11 @@ class ObservableVector2d extends Vector2d {
|
|
|
169
156
|
/**
|
|
170
157
|
* Multiply this vector values by the given scalar
|
|
171
158
|
* @name scale
|
|
172
|
-
* @
|
|
159
|
+
* @memberof me.ObservableVector2d
|
|
173
160
|
* @function
|
|
174
|
-
* @param {
|
|
175
|
-
* @param {
|
|
176
|
-
* @
|
|
161
|
+
* @param {number} x
|
|
162
|
+
* @param {number} [y=x]
|
|
163
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
177
164
|
*/
|
|
178
165
|
scale(x, y) {
|
|
179
166
|
return this._set(this._x * x, this._y * (typeof (y) !== "undefined" ? y : x));
|
|
@@ -182,10 +169,10 @@ class ObservableVector2d extends Vector2d {
|
|
|
182
169
|
/**
|
|
183
170
|
* Multiply this vector values by the passed vector
|
|
184
171
|
* @name scaleV
|
|
185
|
-
* @
|
|
172
|
+
* @memberof me.ObservableVector2d
|
|
186
173
|
* @function
|
|
187
174
|
* @param {me.ObservableVector2d} v
|
|
188
|
-
* @
|
|
175
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
189
176
|
*/
|
|
190
177
|
scaleV(v) {
|
|
191
178
|
return this._set(this._x * v.x, this._y * v.y);
|
|
@@ -194,10 +181,10 @@ class ObservableVector2d extends Vector2d {
|
|
|
194
181
|
/**
|
|
195
182
|
* Divide this vector values by the passed value
|
|
196
183
|
* @name div
|
|
197
|
-
* @
|
|
184
|
+
* @memberof me.ObservableVector2d
|
|
198
185
|
* @function
|
|
199
|
-
* @param {
|
|
200
|
-
* @
|
|
186
|
+
* @param {number} n the value to divide the vector by
|
|
187
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
201
188
|
*/
|
|
202
189
|
div(n) {
|
|
203
190
|
return this._set(this._x / n, this._y / n);
|
|
@@ -206,9 +193,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
206
193
|
/**
|
|
207
194
|
* Update this vector values to absolute values
|
|
208
195
|
* @name abs
|
|
209
|
-
* @
|
|
196
|
+
* @memberof me.ObservableVector2d
|
|
210
197
|
* @function
|
|
211
|
-
* @
|
|
198
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
212
199
|
*/
|
|
213
200
|
abs() {
|
|
214
201
|
return this._set((this._x < 0) ? -this._x : this._x, (this._y < 0) ? -this._y : this._y);
|
|
@@ -217,11 +204,11 @@ class ObservableVector2d extends Vector2d {
|
|
|
217
204
|
/**
|
|
218
205
|
* Clamp the vector value within the specified value range
|
|
219
206
|
* @name clamp
|
|
220
|
-
* @
|
|
207
|
+
* @memberof me.ObservableVector2d
|
|
221
208
|
* @function
|
|
222
|
-
* @param {
|
|
223
|
-
* @param {
|
|
224
|
-
* @
|
|
209
|
+
* @param {number} low
|
|
210
|
+
* @param {number} high
|
|
211
|
+
* @returns {me.ObservableVector2d} new me.ObservableVector2d
|
|
225
212
|
*/
|
|
226
213
|
clamp(low, high) {
|
|
227
214
|
return new ObservableVector2d(clamp(this.x, low, high), clamp(this.y, low, high), {onUpdate: this.onUpdate, scope: this.scope});
|
|
@@ -230,11 +217,11 @@ class ObservableVector2d extends Vector2d {
|
|
|
230
217
|
/**
|
|
231
218
|
* Clamp this vector value within the specified value range
|
|
232
219
|
* @name clampSelf
|
|
233
|
-
* @
|
|
220
|
+
* @memberof me.ObservableVector2d
|
|
234
221
|
* @function
|
|
235
|
-
* @param {
|
|
236
|
-
* @param {
|
|
237
|
-
* @
|
|
222
|
+
* @param {number} low
|
|
223
|
+
* @param {number} high
|
|
224
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
238
225
|
*/
|
|
239
226
|
clampSelf(low, high) {
|
|
240
227
|
return this._set(clamp(this._x, low, high), clamp(this._y, low, high));
|
|
@@ -243,10 +230,10 @@ class ObservableVector2d extends Vector2d {
|
|
|
243
230
|
/**
|
|
244
231
|
* Update this vector with the minimum value between this and the passed vector
|
|
245
232
|
* @name minV
|
|
246
|
-
* @
|
|
233
|
+
* @memberof me.ObservableVector2d
|
|
247
234
|
* @function
|
|
248
235
|
* @param {me.ObservableVector2d} v
|
|
249
|
-
* @
|
|
236
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
250
237
|
*/
|
|
251
238
|
minV(v) {
|
|
252
239
|
return this._set((this._x < v.x) ? this._x : v.x, (this._y < v.y) ? this._y : v.y);
|
|
@@ -255,10 +242,10 @@ class ObservableVector2d extends Vector2d {
|
|
|
255
242
|
/**
|
|
256
243
|
* Update this vector with the maximum value between this and the passed vector
|
|
257
244
|
* @name maxV
|
|
258
|
-
* @
|
|
245
|
+
* @memberof me.ObservableVector2d
|
|
259
246
|
* @function
|
|
260
247
|
* @param {me.ObservableVector2d} v
|
|
261
|
-
* @
|
|
248
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
262
249
|
*/
|
|
263
250
|
maxV(v) {
|
|
264
251
|
return this._set((this._x > v.x) ? this._x : v.x, (this._y > v.y) ? this._y : v.y);
|
|
@@ -267,9 +254,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
267
254
|
/**
|
|
268
255
|
* Floor the vector values
|
|
269
256
|
* @name floor
|
|
270
|
-
* @
|
|
257
|
+
* @memberof me.ObservableVector2d
|
|
271
258
|
* @function
|
|
272
|
-
* @
|
|
259
|
+
* @returns {me.ObservableVector2d} new me.ObservableVector2d
|
|
273
260
|
*/
|
|
274
261
|
floor() {
|
|
275
262
|
return new ObservableVector2d(Math.floor(this._x), Math.floor(this._y), {onUpdate: this.onUpdate, scope: this.scope});
|
|
@@ -278,9 +265,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
278
265
|
/**
|
|
279
266
|
* Floor this vector values
|
|
280
267
|
* @name floorSelf
|
|
281
|
-
* @
|
|
268
|
+
* @memberof me.ObservableVector2d
|
|
282
269
|
* @function
|
|
283
|
-
* @
|
|
270
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
284
271
|
*/
|
|
285
272
|
floorSelf() {
|
|
286
273
|
return this._set(Math.floor(this._x), Math.floor(this._y));
|
|
@@ -289,9 +276,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
289
276
|
/**
|
|
290
277
|
* Ceil the vector values
|
|
291
278
|
* @name ceil
|
|
292
|
-
* @
|
|
279
|
+
* @memberof me.ObservableVector2d
|
|
293
280
|
* @function
|
|
294
|
-
* @
|
|
281
|
+
* @returns {me.ObservableVector2d} new me.ObservableVector2d
|
|
295
282
|
*/
|
|
296
283
|
ceil() {
|
|
297
284
|
return new ObservableVector2d(Math.ceil(this._x), Math.ceil(this._y), {onUpdate: this.onUpdate, scope: this.scope});
|
|
@@ -300,9 +287,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
300
287
|
/**
|
|
301
288
|
* Ceil this vector values
|
|
302
289
|
* @name ceilSelf
|
|
303
|
-
* @
|
|
290
|
+
* @memberof me.ObservableVector2d
|
|
304
291
|
* @function
|
|
305
|
-
* @
|
|
292
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
306
293
|
*/
|
|
307
294
|
ceilSelf() {
|
|
308
295
|
return this._set(Math.ceil(this._x), Math.ceil(this._y));
|
|
@@ -311,9 +298,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
311
298
|
/**
|
|
312
299
|
* Negate the vector values
|
|
313
300
|
* @name negate
|
|
314
|
-
* @
|
|
301
|
+
* @memberof me.ObservableVector2d
|
|
315
302
|
* @function
|
|
316
|
-
* @
|
|
303
|
+
* @returns {me.ObservableVector2d} new me.ObservableVector2d
|
|
317
304
|
*/
|
|
318
305
|
negate() {
|
|
319
306
|
return new ObservableVector2d(-this._x, -this._y, {onUpdate: this.onUpdate, scope: this.scope});
|
|
@@ -322,9 +309,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
322
309
|
/**
|
|
323
310
|
* Negate this vector values
|
|
324
311
|
* @name negateSelf
|
|
325
|
-
* @
|
|
312
|
+
* @memberof me.ObservableVector2d
|
|
326
313
|
* @function
|
|
327
|
-
* @
|
|
314
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
328
315
|
*/
|
|
329
316
|
negateSelf() {
|
|
330
317
|
return this._set(-this._x, -this._y);
|
|
@@ -333,10 +320,10 @@ class ObservableVector2d extends Vector2d {
|
|
|
333
320
|
/**
|
|
334
321
|
* Copy the x,y values of the passed vector to this one
|
|
335
322
|
* @name copy
|
|
336
|
-
* @
|
|
323
|
+
* @memberof me.ObservableVector2d
|
|
337
324
|
* @function
|
|
338
325
|
* @param {me.ObservableVector2d} v
|
|
339
|
-
* @
|
|
326
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
340
327
|
*/
|
|
341
328
|
copy(v) {
|
|
342
329
|
return this._set(v.x, v.y);
|
|
@@ -345,10 +332,10 @@ class ObservableVector2d extends Vector2d {
|
|
|
345
332
|
/**
|
|
346
333
|
* return true if the two vectors are the same
|
|
347
334
|
* @name equals
|
|
348
|
-
* @
|
|
335
|
+
* @memberof me.ObservableVector2d
|
|
349
336
|
* @function
|
|
350
337
|
* @param {me.ObservableVector2d} v
|
|
351
|
-
* @
|
|
338
|
+
* @returns {boolean}
|
|
352
339
|
*/
|
|
353
340
|
equals(v) {
|
|
354
341
|
return ((this._x === v.x) && (this._y === v.y));
|
|
@@ -358,9 +345,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
358
345
|
* change this vector to be perpendicular to what it was before.<br>
|
|
359
346
|
* (Effectively rotates it 90 degrees in a clockwise direction)
|
|
360
347
|
* @name perp
|
|
361
|
-
* @
|
|
348
|
+
* @memberof me.ObservableVector2d
|
|
362
349
|
* @function
|
|
363
|
-
* @
|
|
350
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
364
351
|
*/
|
|
365
352
|
perp() {
|
|
366
353
|
return this._set(this._y, -this._x);
|
|
@@ -369,11 +356,11 @@ class ObservableVector2d extends Vector2d {
|
|
|
369
356
|
/**
|
|
370
357
|
* Rotate this vector (counter-clockwise) by the specified angle (in radians).
|
|
371
358
|
* @name rotate
|
|
372
|
-
* @
|
|
359
|
+
* @memberof me.ObservableVector2d
|
|
373
360
|
* @function
|
|
374
361
|
* @param {number} angle The angle to rotate (in radians)
|
|
375
362
|
* @param {me.Vector2d|me.ObservableVector2d} [v] an optional point to rotate around
|
|
376
|
-
* @
|
|
363
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
377
364
|
*/
|
|
378
365
|
rotate(angle, v) {
|
|
379
366
|
var cx = 0;
|
|
@@ -395,24 +382,36 @@ class ObservableVector2d extends Vector2d {
|
|
|
395
382
|
|
|
396
383
|
/**
|
|
397
384
|
* return the dot product of this vector and the passed one
|
|
398
|
-
* @name
|
|
399
|
-
* @
|
|
385
|
+
* @name dot
|
|
386
|
+
* @memberof me.ObservableVector2d
|
|
400
387
|
* @function
|
|
401
388
|
* @param {me.Vector2d|me.ObservableVector2d} v
|
|
402
|
-
* @
|
|
389
|
+
* @returns {number} The dot product.
|
|
403
390
|
*/
|
|
404
|
-
|
|
391
|
+
dot(v) {
|
|
405
392
|
return this._x * v.x + this._y * v.y;
|
|
406
393
|
}
|
|
407
394
|
|
|
395
|
+
/**
|
|
396
|
+
* return the cross product of this vector and the passed one
|
|
397
|
+
* @name cross
|
|
398
|
+
* @memberof me.ObservableVector2d
|
|
399
|
+
* @function
|
|
400
|
+
* @param {me.Vector2d|me.ObservableVector2d} v
|
|
401
|
+
* @returns {number} The cross product.
|
|
402
|
+
*/
|
|
403
|
+
cross(v) {
|
|
404
|
+
return this._x * v.y - this._y * v.x;
|
|
405
|
+
}
|
|
406
|
+
|
|
408
407
|
/**
|
|
409
408
|
* Linearly interpolate between this vector and the given one.
|
|
410
409
|
* @name lerp
|
|
411
|
-
* @
|
|
410
|
+
* @memberof me.ObservableVector2d
|
|
412
411
|
* @function
|
|
413
412
|
* @param {me.Vector2d|me.ObservableVector2d} v
|
|
414
|
-
* @param {
|
|
415
|
-
* @
|
|
413
|
+
* @param {number} alpha distance along the line (alpha = 0 will be this vector, and alpha = 1 will be the given one).
|
|
414
|
+
* @returns {me.ObservableVector2d} Reference to this object for method chaining
|
|
416
415
|
*/
|
|
417
416
|
lerp(v, alpha) {
|
|
418
417
|
this._x += ( v.x - this._x ) * alpha;
|
|
@@ -423,10 +422,10 @@ class ObservableVector2d extends Vector2d {
|
|
|
423
422
|
/**
|
|
424
423
|
* return the distance between this vector and the passed one
|
|
425
424
|
* @name distance
|
|
426
|
-
* @
|
|
425
|
+
* @memberof me.ObservableVector2d
|
|
427
426
|
* @function
|
|
428
427
|
* @param {me.ObservableVector2d} v
|
|
429
|
-
* @
|
|
428
|
+
* @returns {number}
|
|
430
429
|
*/
|
|
431
430
|
distance(v) {
|
|
432
431
|
return Math.sqrt((this._x - v.x) * (this._x - v.x) + (this._y - v.y) * (this._y - v.y));
|
|
@@ -435,9 +434,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
435
434
|
/**
|
|
436
435
|
* return a clone copy of this vector
|
|
437
436
|
* @name clone
|
|
438
|
-
* @
|
|
437
|
+
* @memberof me.ObservableVector2d
|
|
439
438
|
* @function
|
|
440
|
-
* @
|
|
439
|
+
* @returns {me.ObservableVector2d} new me.ObservableVector2d
|
|
441
440
|
*/
|
|
442
441
|
clone() {
|
|
443
442
|
return pool.pull("ObservableVector2d", this._x, this._y, {onUpdate: this.onUpdate, scope: this.scope});
|
|
@@ -446,9 +445,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
446
445
|
/**
|
|
447
446
|
* return a `me.Vector2d` copy of this `me.ObservableVector2d` object
|
|
448
447
|
* @name toVector2d
|
|
449
|
-
* @
|
|
448
|
+
* @memberof me.ObservableVector2d
|
|
450
449
|
* @function
|
|
451
|
-
* @
|
|
450
|
+
* @returns {me.Vector2d} new me.Vector2d
|
|
452
451
|
*/
|
|
453
452
|
toVector2d() {
|
|
454
453
|
return pool.pull("Vector2d", this._x, this._y);
|
|
@@ -457,9 +456,9 @@ class ObservableVector2d extends Vector2d {
|
|
|
457
456
|
/**
|
|
458
457
|
* convert the object to a string representation
|
|
459
458
|
* @name toString
|
|
460
|
-
* @
|
|
459
|
+
* @memberof me.ObservableVector2d
|
|
461
460
|
* @function
|
|
462
|
-
* @
|
|
461
|
+
* @returns {string}
|
|
463
462
|
*/
|
|
464
463
|
toString() {
|
|
465
464
|
return "x:" + this._x + ",y:" + this._y;
|