melonjs 10.1.1 → 10.2.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 +6 -10
- package/dist/melonjs.js +3114 -2866
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +2588 -2498
- package/dist/melonjs.module.js +2694 -2479
- package/package.json +10 -11
- package/src/audio/audio.js +43 -43
- package/src/camera/camera2d.js +52 -74
- package/src/entity/draggable.js +18 -17
- package/src/entity/droptarget.js +19 -18
- package/src/entity/entity.js +22 -26
- package/src/game.js +3 -3
- package/src/index.js +15 -11
- package/src/input/gamepad.js +13 -13
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -16
- package/src/input/pointer.js +42 -35
- package/src/input/pointerevent.js +25 -33
- package/src/lang/deprecated.js +3 -3
- package/src/level/level.js +24 -16
- package/src/level/tiled/TMXGroup.js +6 -6
- package/src/level/tiled/TMXLayer.js +31 -31
- package/src/level/tiled/TMXObject.js +19 -19
- package/src/level/tiled/TMXTile.js +11 -12
- package/src/level/tiled/TMXTileMap.js +23 -21
- package/src/level/tiled/TMXTileset.js +13 -13
- package/src/level/tiled/TMXTilesetGroup.js +4 -4
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +17 -17
- package/src/loader/loader.js +31 -27
- package/src/loader/loadingscreen.js +44 -75
- package/src/math/color.js +45 -64
- package/src/math/math.js +17 -17
- package/src/math/matrix2.js +46 -46
- package/src/math/matrix3.js +64 -64
- package/src/math/observable_vector2.js +45 -57
- package/src/math/observable_vector3.js +56 -70
- package/src/math/vector2.js +60 -59
- package/src/math/vector3.js +65 -64
- package/src/particles/emitter.js +53 -55
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +45 -51
- package/src/physics/bounds.js +36 -36
- package/src/physics/collision.js +15 -16
- package/src/physics/detector.js +10 -11
- package/src/physics/quadtree.js +18 -16
- package/src/physics/sat.js +17 -17
- package/src/physics/world.js +12 -10
- package/src/plugin/plugin.js +6 -6
- package/src/renderable/GUI.js +13 -18
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +4 -4
- package/src/renderable/container.js +64 -46
- package/src/renderable/imagelayer.js +30 -31
- package/src/renderable/nineslicesprite.js +158 -69
- package/src/renderable/renderable.js +68 -67
- package/src/renderable/sprite.js +57 -43
- package/src/renderable/trigger.js +14 -15
- package/src/shapes/ellipse.js +27 -26
- package/src/shapes/line.js +8 -7
- package/src/shapes/poly.js +33 -31
- package/src/shapes/rectangle.js +50 -96
- package/src/state/stage.js +8 -8
- package/src/state/state.js +56 -56
- package/src/system/device.js +97 -84
- package/src/system/event.js +72 -72
- package/src/system/pooling.js +14 -14
- package/src/system/save.js +6 -3
- package/src/system/timer.js +20 -20
- package/src/text/bitmaptext.js +27 -33
- package/src/text/bitmaptextdata.js +9 -9
- package/src/text/text.js +118 -59
- package/src/tweens/easing.js +4 -4
- package/src/tweens/interpolation.js +4 -4
- package/src/tweens/tween.js +37 -27
- package/src/utils/agent.js +9 -8
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +4 -4
- package/src/utils/function.js +5 -5
- package/src/utils/string.js +12 -12
- package/src/utils/utils.js +19 -19
- package/src/video/canvas/canvas_renderer.js +90 -90
- package/src/video/renderer.js +40 -39
- package/src/video/texture.js +85 -76
- package/src/video/texture_cache.js +11 -0
- package/src/video/video.js +31 -31
- package/src/video/webgl/buffer/vertex.js +9 -1
- package/src/video/webgl/glshader.js +20 -20
- package/src/video/webgl/webgl_compositor.js +47 -46
- package/src/video/webgl/webgl_renderer.js +104 -104
package/src/shapes/rectangle.js
CHANGED
|
@@ -8,10 +8,10 @@ import Polygon from "./poly.js";
|
|
|
8
8
|
* @extends me.Polygon
|
|
9
9
|
* @memberOf me
|
|
10
10
|
* @constructor
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {
|
|
11
|
+
* @param {number} x position of the Rectangle
|
|
12
|
+
* @param {number} y position of the Rectangle
|
|
13
|
+
* @param {number} w width of the rectangle
|
|
14
|
+
* @param {number} h height of the rectangle
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
class Rect extends Polygon {
|
|
@@ -37,11 +37,11 @@ class Rect extends Polygon {
|
|
|
37
37
|
* @name setShape
|
|
38
38
|
* @memberOf me.Rect.prototype
|
|
39
39
|
* @function
|
|
40
|
-
* @param {
|
|
41
|
-
* @param {
|
|
42
|
-
* @param {
|
|
43
|
-
* @param {
|
|
44
|
-
* @
|
|
40
|
+
* @param {number} x position of the Rectangle
|
|
41
|
+
* @param {number} y position of the Rectangle
|
|
42
|
+
* @param {number|me.Vector2d[]} w width of the rectangle, or an array of vector defining the rectangle
|
|
43
|
+
* @param {number} [h] height of the rectangle, if a numeral width parameter is specified
|
|
44
|
+
* @returns {me.Rect} this rectangle
|
|
45
45
|
*/
|
|
46
46
|
setShape(x, y, w, h) {
|
|
47
47
|
var points = w; // assume w is an array by default
|
|
@@ -64,14 +64,10 @@ class Rect extends Polygon {
|
|
|
64
64
|
/**
|
|
65
65
|
* left coordinate of the Rectangle
|
|
66
66
|
* @public
|
|
67
|
-
* @type {
|
|
67
|
+
* @type {number}
|
|
68
68
|
* @name left
|
|
69
69
|
* @memberOf me.Rect
|
|
70
70
|
*/
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @ignore
|
|
74
|
-
*/
|
|
75
71
|
get left() {
|
|
76
72
|
return this.pos.x;
|
|
77
73
|
}
|
|
@@ -79,14 +75,10 @@ class Rect extends Polygon {
|
|
|
79
75
|
/**
|
|
80
76
|
* right coordinate of the Rectangle
|
|
81
77
|
* @public
|
|
82
|
-
* @type {
|
|
78
|
+
* @type {number}
|
|
83
79
|
* @name right
|
|
84
80
|
* @memberOf me.Rect
|
|
85
81
|
*/
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @ignore
|
|
89
|
-
*/
|
|
90
82
|
get right() {
|
|
91
83
|
var w = this.width;
|
|
92
84
|
return (this.pos.x + w) || w;
|
|
@@ -95,14 +87,10 @@ class Rect extends Polygon {
|
|
|
95
87
|
/**
|
|
96
88
|
* top coordinate of the Rectangle
|
|
97
89
|
* @public
|
|
98
|
-
* @type {
|
|
90
|
+
* @type {number}
|
|
99
91
|
* @name top
|
|
100
92
|
* @memberOf me.Rect
|
|
101
93
|
*/
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @ignore
|
|
105
|
-
*/
|
|
106
94
|
get top() {
|
|
107
95
|
return this.pos.y;
|
|
108
96
|
}
|
|
@@ -110,14 +98,10 @@ class Rect extends Polygon {
|
|
|
110
98
|
/**
|
|
111
99
|
* bottom coordinate of the Rectangle
|
|
112
100
|
* @public
|
|
113
|
-
* @type {
|
|
101
|
+
* @type {number}
|
|
114
102
|
* @name bottom
|
|
115
103
|
* @memberOf me.Rect
|
|
116
104
|
*/
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* @ignore
|
|
120
|
-
*/
|
|
121
105
|
get bottom() {
|
|
122
106
|
var h = this.height;
|
|
123
107
|
return (this.pos.y + h) || h;
|
|
@@ -126,20 +110,13 @@ class Rect extends Polygon {
|
|
|
126
110
|
/**
|
|
127
111
|
* width of the Rectangle
|
|
128
112
|
* @public
|
|
129
|
-
* @type {
|
|
113
|
+
* @type {number}
|
|
130
114
|
* @name width
|
|
131
115
|
* @memberOf me.Rect
|
|
132
116
|
*/
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @ignore
|
|
136
|
-
*/
|
|
137
117
|
get width() {
|
|
138
118
|
return this.points[2].x;
|
|
139
119
|
}
|
|
140
|
-
/**
|
|
141
|
-
* @ignore
|
|
142
|
-
*/
|
|
143
120
|
set width(value) {
|
|
144
121
|
this.points[1].x = this.points[2].x = value;
|
|
145
122
|
this.recalc();
|
|
@@ -149,20 +126,13 @@ class Rect extends Polygon {
|
|
|
149
126
|
/**
|
|
150
127
|
* height of the Rectangle
|
|
151
128
|
* @public
|
|
152
|
-
* @type {
|
|
129
|
+
* @type {number}
|
|
153
130
|
* @name height
|
|
154
131
|
* @memberOf me.Rect
|
|
155
132
|
*/
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* @ignore
|
|
159
|
-
*/
|
|
160
133
|
get height() {
|
|
161
134
|
return this.points[2].y;
|
|
162
135
|
}
|
|
163
|
-
/**
|
|
164
|
-
* @ignore
|
|
165
|
-
*/
|
|
166
136
|
set height(value) {
|
|
167
137
|
this.points[2].y = this.points[3].y = value;
|
|
168
138
|
this.recalc();
|
|
@@ -172,14 +142,10 @@ class Rect extends Polygon {
|
|
|
172
142
|
/**
|
|
173
143
|
* absolute center of this rectangle on the horizontal axis
|
|
174
144
|
* @public
|
|
175
|
-
* @type {
|
|
145
|
+
* @type {number}
|
|
176
146
|
* @name centerX
|
|
177
147
|
* @memberOf me.Rect
|
|
178
148
|
*/
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @ignore
|
|
182
|
-
*/
|
|
183
149
|
get centerX() {
|
|
184
150
|
if (isFinite(this.width)) {
|
|
185
151
|
return this.pos.x + (this.width / 2);
|
|
@@ -187,10 +153,6 @@ class Rect extends Polygon {
|
|
|
187
153
|
return this.width;
|
|
188
154
|
}
|
|
189
155
|
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* @ignore
|
|
193
|
-
*/
|
|
194
156
|
set centerX (value) {
|
|
195
157
|
this.pos.x = value - (this.width / 2);
|
|
196
158
|
}
|
|
@@ -198,14 +160,10 @@ class Rect extends Polygon {
|
|
|
198
160
|
/**
|
|
199
161
|
* absolute center of this rectangle on the vertical axis
|
|
200
162
|
* @public
|
|
201
|
-
* @type {
|
|
163
|
+
* @type {number}
|
|
202
164
|
* @name centerY
|
|
203
165
|
* @memberOf me.Rect
|
|
204
166
|
*/
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @ignore
|
|
208
|
-
*/
|
|
209
167
|
get centerY() {
|
|
210
168
|
if (isFinite(this.height)) {
|
|
211
169
|
return this.pos.y + (this.height / 2);
|
|
@@ -213,10 +171,6 @@ class Rect extends Polygon {
|
|
|
213
171
|
return this.height;
|
|
214
172
|
}
|
|
215
173
|
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* @ignore
|
|
219
|
-
*/
|
|
220
174
|
set centerY(value) {
|
|
221
175
|
this.pos.y = value - (this.height / 2);
|
|
222
176
|
}
|
|
@@ -226,9 +180,9 @@ class Rect extends Polygon {
|
|
|
226
180
|
* @name resize
|
|
227
181
|
* @memberOf me.Rect.prototype
|
|
228
182
|
* @function
|
|
229
|
-
* @param {
|
|
230
|
-
* @param {
|
|
231
|
-
* @
|
|
183
|
+
* @param {number} w new width of the rectangle
|
|
184
|
+
* @param {number} h new height of the rectangle
|
|
185
|
+
* @returns {me.Rect} this rectangle
|
|
232
186
|
*/
|
|
233
187
|
resize(w, h) {
|
|
234
188
|
this.width = w;
|
|
@@ -241,9 +195,9 @@ class Rect extends Polygon {
|
|
|
241
195
|
* @name scale
|
|
242
196
|
* @memberOf me.Rect.prototype
|
|
243
197
|
* @function
|
|
244
|
-
* @param {
|
|
245
|
-
* @param {
|
|
246
|
-
* @
|
|
198
|
+
* @param {number} x a number representing the abscissa of the scaling vector.
|
|
199
|
+
* @param {number} [y=x] a number representing the ordinate of the scaling vector.
|
|
200
|
+
* @returns {me.Rect} this rectangle
|
|
247
201
|
*/
|
|
248
202
|
scale(x, y = x) {
|
|
249
203
|
this.width *= x;
|
|
@@ -256,7 +210,7 @@ class Rect extends Polygon {
|
|
|
256
210
|
* @name clone
|
|
257
211
|
* @memberOf me.Rect.prototype
|
|
258
212
|
* @function
|
|
259
|
-
* @
|
|
213
|
+
* @returns {me.Rect} new rectangle
|
|
260
214
|
*/
|
|
261
215
|
clone() {
|
|
262
216
|
return new Rect(this.pos.x, this.pos.y, this.width, this.height);
|
|
@@ -268,7 +222,7 @@ class Rect extends Polygon {
|
|
|
268
222
|
* @memberOf me.Rect.prototype
|
|
269
223
|
* @function
|
|
270
224
|
* @param {me.Rect} rect Source rectangle
|
|
271
|
-
* @
|
|
225
|
+
* @returns {me.Rect} new rectangle
|
|
272
226
|
*/
|
|
273
227
|
copy(rect) {
|
|
274
228
|
return this.setShape(rect.pos.x, rect.pos.y, rect.width, rect.height);
|
|
@@ -280,15 +234,15 @@ class Rect extends Polygon {
|
|
|
280
234
|
* @memberOf me.Rect.prototype
|
|
281
235
|
* @function
|
|
282
236
|
* @param {me.Rect} rect other rectangle to union with
|
|
283
|
-
* @
|
|
237
|
+
* @returns {me.Rect} the union(ed) rectangle
|
|
284
238
|
*/
|
|
285
|
-
union(
|
|
286
|
-
var x1 = Math.min(this.left,
|
|
287
|
-
var y1 = Math.min(this.top,
|
|
239
|
+
union(rect) {
|
|
240
|
+
var x1 = Math.min(this.left, rect.left);
|
|
241
|
+
var y1 = Math.min(this.top, rect.top);
|
|
288
242
|
|
|
289
243
|
this.resize(
|
|
290
|
-
Math.max(this.right,
|
|
291
|
-
Math.max(this.bottom,
|
|
244
|
+
Math.max(this.right, rect.right) - x1,
|
|
245
|
+
Math.max(this.bottom, rect.bottom) - y1
|
|
292
246
|
);
|
|
293
247
|
|
|
294
248
|
this.pos.set(x1, y1);
|
|
@@ -302,14 +256,14 @@ class Rect extends Polygon {
|
|
|
302
256
|
* @memberOf me.Rect.prototype
|
|
303
257
|
* @function
|
|
304
258
|
* @param {me.Rect} rect
|
|
305
|
-
* @
|
|
259
|
+
* @returns {boolean} true if overlaps
|
|
306
260
|
*/
|
|
307
|
-
overlaps(
|
|
261
|
+
overlaps(rect) {
|
|
308
262
|
return (
|
|
309
|
-
this.left <
|
|
310
|
-
|
|
311
|
-
this.top <
|
|
312
|
-
|
|
263
|
+
this.left < rect.right &&
|
|
264
|
+
rect.left < this.right &&
|
|
265
|
+
this.top < rect.bottom &&
|
|
266
|
+
rect.top < this.bottom
|
|
313
267
|
);
|
|
314
268
|
}
|
|
315
269
|
|
|
@@ -319,7 +273,7 @@ class Rect extends Polygon {
|
|
|
319
273
|
* @memberOf me.Rect.prototype
|
|
320
274
|
* @function
|
|
321
275
|
* @param {me.Rect} rect
|
|
322
|
-
* @
|
|
276
|
+
* @returns {boolean} true if contains
|
|
323
277
|
*/
|
|
324
278
|
|
|
325
279
|
/**
|
|
@@ -327,9 +281,9 @@ class Rect extends Polygon {
|
|
|
327
281
|
* @name contains
|
|
328
282
|
* @memberOf me.Rect.prototype
|
|
329
283
|
* @function
|
|
330
|
-
* @param {
|
|
331
|
-
* @param {
|
|
332
|
-
* @
|
|
284
|
+
* @param {number} x x coordinate
|
|
285
|
+
* @param {number} y y coordinate
|
|
286
|
+
* @returns {boolean} true if contains
|
|
333
287
|
*/
|
|
334
288
|
|
|
335
289
|
/**
|
|
@@ -338,7 +292,7 @@ class Rect extends Polygon {
|
|
|
338
292
|
* @memberOf me.Rect
|
|
339
293
|
* @function
|
|
340
294
|
* @param {me.Vector2d} point
|
|
341
|
-
* @
|
|
295
|
+
* @returns {boolean} true if contains
|
|
342
296
|
*/
|
|
343
297
|
contains() {
|
|
344
298
|
var arg0 = arguments[0];
|
|
@@ -374,14 +328,14 @@ class Rect extends Polygon {
|
|
|
374
328
|
* @memberOf me.Rect.prototype
|
|
375
329
|
* @function
|
|
376
330
|
* @param {me.Rect} rect
|
|
377
|
-
* @
|
|
331
|
+
* @returns {boolean} true if equals
|
|
378
332
|
*/
|
|
379
|
-
equals(
|
|
333
|
+
equals(rect) {
|
|
380
334
|
return (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
335
|
+
rect.left === this.left &&
|
|
336
|
+
rect.right === this.right &&
|
|
337
|
+
rect.top === this.top &&
|
|
338
|
+
rect.bottom === this.bottom
|
|
385
339
|
);
|
|
386
340
|
}
|
|
387
341
|
|
|
@@ -390,7 +344,7 @@ class Rect extends Polygon {
|
|
|
390
344
|
* @name isFinite
|
|
391
345
|
* @memberOf me.Rect.prototype
|
|
392
346
|
* @function
|
|
393
|
-
* @
|
|
347
|
+
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
394
348
|
*/
|
|
395
349
|
isFinite() {
|
|
396
350
|
return (isFinite(this.pos.x) && isFinite(this.pos.y) && isFinite(this.width) && isFinite(this.height));
|
|
@@ -401,7 +355,7 @@ class Rect extends Polygon {
|
|
|
401
355
|
* @name toPolygon
|
|
402
356
|
* @memberOf me.Rect.prototype
|
|
403
357
|
* @function
|
|
404
|
-
* @
|
|
358
|
+
* @returns {me.Polygon} a new Polygon that represents this rectangle.
|
|
405
359
|
*/
|
|
406
360
|
toPolygon() {
|
|
407
361
|
return new Polygon(
|
package/src/state/stage.js
CHANGED
|
@@ -19,8 +19,8 @@ var default_settings = {
|
|
|
19
19
|
* @extends me.Object
|
|
20
20
|
* @memberOf me
|
|
21
21
|
* @constructor
|
|
22
|
-
* @param {
|
|
23
|
-
* @param {
|
|
22
|
+
* @param {object} [options] The stage` parameters
|
|
23
|
+
* @param {me.Camera2d[]} [options.cameras=[new me.Camera2d()]] a list of cameras (experimental)
|
|
24
24
|
* @param {Function} [options.onResetEvent] called by the state manager when reseting the object
|
|
25
25
|
* @param {Function} [options.onDestroyEvent] called by the state manager before switching to another state
|
|
26
26
|
* @see me.state
|
|
@@ -47,7 +47,7 @@ class Stage {
|
|
|
47
47
|
* @public
|
|
48
48
|
* @name settings
|
|
49
49
|
* @memberOf me.Stage
|
|
50
|
-
* @
|
|
50
|
+
* @type {object}
|
|
51
51
|
*/
|
|
52
52
|
this.settings = Object.assign(default_settings, settings || {});
|
|
53
53
|
}
|
|
@@ -57,7 +57,7 @@ class Stage {
|
|
|
57
57
|
* @ignore
|
|
58
58
|
*/
|
|
59
59
|
reset() {
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
// add all defined cameras
|
|
62
62
|
this.settings.cameras.forEach((camera) => {
|
|
63
63
|
this.cameras.set(camera.name, camera);
|
|
@@ -87,9 +87,9 @@ class Stage {
|
|
|
87
87
|
* @memberOf me.Stage
|
|
88
88
|
* @ignore
|
|
89
89
|
* @function
|
|
90
|
-
* @param {
|
|
91
|
-
* @
|
|
92
|
-
|
|
90
|
+
* @param {number} dt time since the last update in milliseconds.
|
|
91
|
+
* @returns {boolean}
|
|
92
|
+
*/
|
|
93
93
|
update(dt) {
|
|
94
94
|
// update all objects (and pass the elapsed time since last frame)
|
|
95
95
|
var isDirty = game.world.update(dt);
|
|
@@ -139,7 +139,7 @@ class Stage {
|
|
|
139
139
|
* @name onResetEvent
|
|
140
140
|
* @memberOf me.Stage
|
|
141
141
|
* @function
|
|
142
|
-
* @param {} [arguments
|
|
142
|
+
* @param {object} [...arguments] optional arguments passed when switching state
|
|
143
143
|
* @see me.state#change
|
|
144
144
|
*/
|
|
145
145
|
onResetEvent() {
|
package/src/state/state.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as event from "./../system/event.js";
|
|
|
4
4
|
import timer from "./../system/timer.js";
|
|
5
5
|
import * as game from "./../game.js";
|
|
6
6
|
import Stage from "./../state/stage.js";
|
|
7
|
-
import
|
|
7
|
+
import DefaultLoadingScreen from "./../loader/loadingscreen.js";
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
// current state
|
|
@@ -74,7 +74,7 @@ function _pauseRunLoop() {
|
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* this is only called when using requestAnimFrame stuff
|
|
77
|
-
* @param {
|
|
77
|
+
* @param {number} time current timestamp in milliseconds
|
|
78
78
|
* @ignore
|
|
79
79
|
*/
|
|
80
80
|
function _renderFrame(time) {
|
|
@@ -137,7 +137,7 @@ function _switchState(state) {
|
|
|
137
137
|
// initialize me.state on system boot
|
|
138
138
|
event.on(event.BOOT, () => {
|
|
139
139
|
// set the built-in loading stage
|
|
140
|
-
state.set(state.LOADING,
|
|
140
|
+
state.set(state.LOADING, new DefaultLoadingScreen());
|
|
141
141
|
// set and enable the default stage
|
|
142
142
|
state.set(state.DEFAULT, new Stage());
|
|
143
143
|
// enable by default as soon as the display is initialized
|
|
@@ -255,15 +255,16 @@ var state = {
|
|
|
255
255
|
* @memberOf me.state
|
|
256
256
|
* @public
|
|
257
257
|
* @function
|
|
258
|
-
* @param {
|
|
258
|
+
* @param {boolean} [pauseTrack=false] pause current track on screen stop.
|
|
259
259
|
*/
|
|
260
|
-
stop(
|
|
260
|
+
stop(pauseTrack=false) {
|
|
261
261
|
// only stop when we are not loading stuff
|
|
262
262
|
if ((_state !== this.LOADING) && this.isRunning()) {
|
|
263
263
|
// stop the main loop
|
|
264
264
|
_stopRunLoop();
|
|
265
|
+
|
|
265
266
|
// current music stop
|
|
266
|
-
if (
|
|
267
|
+
if (pauseTrack === true) {
|
|
267
268
|
pauseTrack();
|
|
268
269
|
}
|
|
269
270
|
|
|
@@ -281,9 +282,9 @@ var state = {
|
|
|
281
282
|
* @memberOf me.state
|
|
282
283
|
* @public
|
|
283
284
|
* @function
|
|
284
|
-
* @param {
|
|
285
|
+
* @param {boolean} [music=false] pause current music track on screen pause
|
|
285
286
|
*/
|
|
286
|
-
pause(music) {
|
|
287
|
+
pause(music=false) {
|
|
287
288
|
// only pause when we are not loading stuff
|
|
288
289
|
if ((_state !== this.LOADING) && !this.isPaused()) {
|
|
289
290
|
// stop the main loop
|
|
@@ -307,9 +308,9 @@ var state = {
|
|
|
307
308
|
* @memberOf me.state
|
|
308
309
|
* @public
|
|
309
310
|
* @function
|
|
310
|
-
* @param {
|
|
311
|
+
* @param {boolean} [music=false] resume current music track on screen resume
|
|
311
312
|
*/
|
|
312
|
-
restart(music) {
|
|
313
|
+
restart(music=false) {
|
|
313
314
|
if (!this.isRunning()) {
|
|
314
315
|
// restart the main loop
|
|
315
316
|
_startRunLoop();
|
|
@@ -335,9 +336,9 @@ var state = {
|
|
|
335
336
|
* @memberOf me.state
|
|
336
337
|
* @public
|
|
337
338
|
* @function
|
|
338
|
-
* @param {
|
|
339
|
+
* @param {boolean} [music=false] resume current music track on screen resume
|
|
339
340
|
*/
|
|
340
|
-
resume(music) {
|
|
341
|
+
resume(music=false) {
|
|
341
342
|
if (this.isPaused()) {
|
|
342
343
|
// resume the main loop
|
|
343
344
|
_resumeRunLoop();
|
|
@@ -360,7 +361,7 @@ var state = {
|
|
|
360
361
|
* @memberOf me.state
|
|
361
362
|
* @public
|
|
362
363
|
* @function
|
|
363
|
-
* @
|
|
364
|
+
* @returns {boolean} true if a "process is running"
|
|
364
365
|
*/
|
|
365
366
|
isRunning() {
|
|
366
367
|
return _animFrameId !== -1;
|
|
@@ -372,7 +373,7 @@ var state = {
|
|
|
372
373
|
* @memberOf me.state
|
|
373
374
|
* @public
|
|
374
375
|
* @function
|
|
375
|
-
* @
|
|
376
|
+
* @returns {boolean} true if the game is paused
|
|
376
377
|
*/
|
|
377
378
|
isPaused() {
|
|
378
379
|
return _isPaused;
|
|
@@ -384,9 +385,9 @@ var state = {
|
|
|
384
385
|
* @memberOf me.state
|
|
385
386
|
* @public
|
|
386
387
|
* @function
|
|
387
|
-
* @param {
|
|
388
|
+
* @param {number} state State ID (see constants)
|
|
388
389
|
* @param {me.Stage} stage Instantiated Stage to associate with state ID
|
|
389
|
-
* @param {
|
|
390
|
+
* @param {boolean} [start = false] if true the state will be changed immediately after adding it.
|
|
390
391
|
* @example
|
|
391
392
|
* class MenuButton extends me.GUI_Object {
|
|
392
393
|
* onClick() {
|
|
@@ -444,7 +445,7 @@ var state = {
|
|
|
444
445
|
* @memberOf me.state
|
|
445
446
|
* @public
|
|
446
447
|
* @function
|
|
447
|
-
* @
|
|
448
|
+
* @returns {me.Stage}
|
|
448
449
|
*/
|
|
449
450
|
current() {
|
|
450
451
|
if (typeof _stages[_state] !== "undefined") {
|
|
@@ -458,9 +459,9 @@ var state = {
|
|
|
458
459
|
* @memberOf me.state
|
|
459
460
|
* @public
|
|
460
461
|
* @function
|
|
461
|
-
* @param {
|
|
462
|
-
* @param {me.Color|
|
|
463
|
-
* @param {
|
|
462
|
+
* @param {string} effect (only "fade" is supported for now)
|
|
463
|
+
* @param {me.Color|string} color a CSS color value
|
|
464
|
+
* @param {number} [duration=1000] expressed in milliseconds
|
|
464
465
|
*/
|
|
465
466
|
transition(effect, color, duration) {
|
|
466
467
|
if (effect === "fade") {
|
|
@@ -475,8 +476,8 @@ var state = {
|
|
|
475
476
|
* @memberOf me.state
|
|
476
477
|
* @public
|
|
477
478
|
* @function
|
|
478
|
-
* @param {
|
|
479
|
-
* @param {
|
|
479
|
+
* @param {number} state State ID (see constants)
|
|
480
|
+
* @param {boolean} enable
|
|
480
481
|
*/
|
|
481
482
|
setTransition(state, enable) {
|
|
482
483
|
_stages[state].transition = enable;
|
|
@@ -488,9 +489,9 @@ var state = {
|
|
|
488
489
|
* @memberOf me.state
|
|
489
490
|
* @public
|
|
490
491
|
* @function
|
|
491
|
-
* @param {
|
|
492
|
-
* @param {
|
|
493
|
-
* @param {} [arguments
|
|
492
|
+
* @param {number} state State ID (see constants)
|
|
493
|
+
* @param {boolean} forceChange if true the state will be changed immediately
|
|
494
|
+
* @param {object} [...arguments] extra arguments to be passed to the reset functions
|
|
494
495
|
* @example
|
|
495
496
|
* // The onResetEvent method on the play screen will receive two args:
|
|
496
497
|
* // "level_1" and the number 3
|
|
@@ -502,39 +503,37 @@ var state = {
|
|
|
502
503
|
throw new Error("Undefined Stage for state '" + state + "'");
|
|
503
504
|
}
|
|
504
505
|
|
|
505
|
-
if
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
506
|
+
// do nothing if already the current state
|
|
507
|
+
if (!this.isCurrent(state)) {
|
|
508
|
+
_extraArgs = null;
|
|
509
|
+
if (arguments.length > 1) {
|
|
510
|
+
// store extra arguments if any
|
|
511
|
+
_extraArgs = Array.prototype.slice.call(arguments, 1);
|
|
512
|
+
}
|
|
513
|
+
// if fading effect
|
|
514
|
+
if (_fade.duration && _stages[state].transition) {
|
|
515
|
+
/** @ignore */
|
|
516
|
+
_onSwitchComplete = function() {
|
|
517
|
+
game.viewport.fadeOut(_fade.color, _fade.duration);
|
|
518
|
+
};
|
|
519
|
+
game.viewport.fadeIn(
|
|
520
|
+
_fade.color,
|
|
521
|
+
_fade.duration,
|
|
522
|
+
function () {
|
|
523
|
+
fctUtil.defer(_switchState, this, state);
|
|
524
|
+
}
|
|
525
|
+
);
|
|
509
526
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
_onSwitchComplete = function() {
|
|
519
|
-
game.viewport.fadeOut(_fade.color, _fade.duration);
|
|
520
|
-
};
|
|
521
|
-
game.viewport.fadeIn(
|
|
522
|
-
_fade.color,
|
|
523
|
-
_fade.duration,
|
|
524
|
-
function () {
|
|
527
|
+
}
|
|
528
|
+
// else just switch without any effects
|
|
529
|
+
else {
|
|
530
|
+
// wait for the last frame to be
|
|
531
|
+
// "finished" before switching
|
|
532
|
+
if (forceChange === true) {
|
|
533
|
+
_switchState(state);
|
|
534
|
+
} else {
|
|
525
535
|
fctUtil.defer(_switchState, this, state);
|
|
526
536
|
}
|
|
527
|
-
);
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
// else just switch without any effects
|
|
531
|
-
else {
|
|
532
|
-
// wait for the last frame to be
|
|
533
|
-
// "finished" before switching
|
|
534
|
-
if (forceChange === true) {
|
|
535
|
-
_switchState(state);
|
|
536
|
-
} else {
|
|
537
|
-
fctUtil.defer(_switchState, this, state);
|
|
538
537
|
}
|
|
539
538
|
}
|
|
540
539
|
},
|
|
@@ -545,7 +544,8 @@ var state = {
|
|
|
545
544
|
* @memberOf me.state
|
|
546
545
|
* @public
|
|
547
546
|
* @function
|
|
548
|
-
* @param {
|
|
547
|
+
* @param {number} state State ID (see constants)
|
|
548
|
+
* @returns {boolean} true if the specified state is the current one
|
|
549
549
|
*/
|
|
550
550
|
isCurrent(state) {
|
|
551
551
|
return _state === state;
|