melonjs 9.1.0 → 10.0.1
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/{LICENSE → LICENSE.md} +0 -0
- package/README.md +93 -57
- package/dist/melonjs.js +10334 -11179
- package/dist/melonjs.min.js +4 -10
- package/dist/melonjs.module.d.ts +13206 -0
- package/dist/melonjs.module.js +9913 -10872
- package/package.json +19 -14
- package/src/audio/audio.js +477 -553
- package/src/camera/camera2d.js +67 -65
- package/src/entity/draggable.js +26 -35
- package/src/entity/droptarget.js +17 -14
- package/src/entity/entity.js +59 -79
- package/src/game.js +194 -204
- package/src/index.js +12 -30
- package/src/input/gamepad.js +8 -19
- package/src/input/keyboard.js +4 -4
- package/src/input/pointer.js +14 -12
- package/src/input/pointerevent.js +15 -13
- package/src/lang/deprecated.js +2 -887
- package/src/level/level.js +3 -3
- package/src/level/tiled/TMXGroup.js +7 -11
- package/src/level/tiled/TMXLayer.js +33 -32
- package/src/level/tiled/TMXTileMap.js +15 -19
- package/src/level/tiled/TMXTileset.js +5 -5
- package/src/level/tiled/TMXUtils.js +3 -3
- package/src/level/tiled/renderer/TMXRenderer.js +4 -0
- package/src/loader/loader.js +8 -23
- package/src/loader/loadingscreen.js +51 -60
- package/src/math/matrix3.js +1 -1
- package/src/particles/emitter.js +36 -39
- package/src/particles/particle.js +27 -12
- package/src/particles/particlecontainer.js +17 -16
- package/src/physics/body.js +80 -118
- package/src/physics/collision.js +5 -235
- package/src/physics/detector.js +235 -0
- package/src/physics/quadtree.js +14 -14
- package/src/physics/world.js +84 -18
- package/src/plugin/plugin.js +26 -24
- package/src/polyfill/console.js +9 -14
- package/src/renderable/GUI.js +48 -62
- package/src/renderable/collectable.js +11 -4
- package/src/renderable/colorlayer.js +28 -26
- package/src/renderable/container.js +120 -96
- package/src/renderable/imagelayer.js +94 -93
- package/src/renderable/renderable.js +164 -138
- package/src/renderable/sprite.js +42 -44
- package/src/renderable/trigger.js +24 -17
- package/src/shapes/ellipse.js +27 -27
- package/src/shapes/line.js +12 -8
- package/src/shapes/poly.js +77 -49
- package/src/shapes/rectangle.js +193 -268
- package/src/state/stage.js +23 -25
- package/src/state/state.js +35 -86
- package/src/system/device.js +233 -285
- package/src/system/event.js +485 -432
- package/src/system/pooling.js +61 -54
- package/src/system/save.js +17 -16
- package/src/system/timer.js +34 -38
- package/src/text/bitmaptext.js +44 -46
- package/src/text/text.js +39 -34
- package/src/tweens/easing.js +0 -2
- package/src/tweens/interpolation.js +3 -8
- package/src/tweens/tween.js +332 -351
- package/src/utils/function.js +6 -8
- package/src/utils/utils.js +34 -30
- package/src/video/canvas/canvas_renderer.js +13 -8
- package/src/video/renderer.js +8 -7
- package/src/video/texture.js +8 -8
- package/src/video/texture_cache.js +5 -5
- package/src/video/video.js +373 -403
- package/src/video/webgl/glshader.js +2 -2
- package/src/video/webgl/webgl_compositor.js +14 -8
- package/src/video/webgl/webgl_renderer.js +21 -19
- package/plugins/debug/debugPanel.js +0 -770
- package/plugins/debug/font/PressStart2P.fnt +0 -100
- package/plugins/debug/font/PressStart2P.ltr +0 -1
- package/plugins/debug/font/PressStart2P.png +0 -0
- package/plugins/debug/particleDebugPanel.js +0 -303
package/src/state/stage.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import game from "./../game.js";
|
|
1
|
+
import { renderer } from "./../video/video.js";
|
|
2
|
+
import * as game from "./../game.js";
|
|
3
3
|
import Camera2d from "./../camera/camera2d.js";
|
|
4
|
-
import "jay-extend";
|
|
5
|
-
|
|
6
4
|
|
|
7
5
|
// a default camera instance to use across all stages
|
|
8
6
|
var default_camera;
|
|
@@ -27,11 +25,12 @@ var default_settings = {
|
|
|
27
25
|
* @param {Function} [options.onDestroyEvent] called by the state manager before switching to another state
|
|
28
26
|
* @see me.state
|
|
29
27
|
*/
|
|
30
|
-
|
|
28
|
+
class Stage {
|
|
29
|
+
|
|
31
30
|
/**
|
|
32
31
|
* @ignore
|
|
33
32
|
*/
|
|
34
|
-
|
|
33
|
+
constructor(settings) {
|
|
35
34
|
/**
|
|
36
35
|
* The list of active cameras in this stage.
|
|
37
36
|
* Cameras will be renderered based on this order defined in this list.
|
|
@@ -51,25 +50,24 @@ var Stage = window.Jay.extend({
|
|
|
51
50
|
* @enum {Object}
|
|
52
51
|
*/
|
|
53
52
|
this.settings = Object.assign(default_settings, settings || {});
|
|
54
|
-
}
|
|
53
|
+
}
|
|
55
54
|
|
|
56
55
|
/**
|
|
57
56
|
* Object reset function
|
|
58
57
|
* @ignore
|
|
59
58
|
*/
|
|
60
|
-
reset
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
reset() {
|
|
60
|
+
|
|
63
61
|
// add all defined cameras
|
|
64
|
-
this.settings.cameras.forEach(
|
|
65
|
-
|
|
62
|
+
this.settings.cameras.forEach((camera) => {
|
|
63
|
+
this.cameras.set(camera.name, camera);
|
|
66
64
|
});
|
|
67
65
|
|
|
68
66
|
// empty or no default camera
|
|
69
67
|
if (this.cameras.has("default") === false) {
|
|
70
68
|
if (typeof default_camera === "undefined") {
|
|
71
|
-
var width =
|
|
72
|
-
var height =
|
|
69
|
+
var width = renderer.getWidth();
|
|
70
|
+
var height = renderer.getHeight();
|
|
73
71
|
// new default camera instance
|
|
74
72
|
default_camera = new Camera2d(0, 0, width, height);
|
|
75
73
|
}
|
|
@@ -81,7 +79,7 @@ var Stage = window.Jay.extend({
|
|
|
81
79
|
|
|
82
80
|
// call the onReset Function
|
|
83
81
|
this.onResetEvent.apply(this, arguments);
|
|
84
|
-
}
|
|
82
|
+
}
|
|
85
83
|
|
|
86
84
|
/**
|
|
87
85
|
* update function
|
|
@@ -92,7 +90,7 @@ var Stage = window.Jay.extend({
|
|
|
92
90
|
* @param {Number} dt time since the last update in milliseconds.
|
|
93
91
|
* @return false
|
|
94
92
|
**/
|
|
95
|
-
update
|
|
93
|
+
update(dt) {
|
|
96
94
|
// update all objects (and pass the elapsed time since last frame)
|
|
97
95
|
var isDirty = game.world.update(dt);
|
|
98
96
|
|
|
@@ -105,7 +103,7 @@ var Stage = window.Jay.extend({
|
|
|
105
103
|
});
|
|
106
104
|
|
|
107
105
|
return isDirty;
|
|
108
|
-
}
|
|
106
|
+
}
|
|
109
107
|
|
|
110
108
|
/**
|
|
111
109
|
* draw the current stage
|
|
@@ -115,24 +113,24 @@ var Stage = window.Jay.extend({
|
|
|
115
113
|
* @function
|
|
116
114
|
* @param {me.CanvasRenderer|me.WebGLRenderer} renderer a renderer object
|
|
117
115
|
*/
|
|
118
|
-
draw
|
|
116
|
+
draw(renderer) {
|
|
119
117
|
// iterate through all cameras
|
|
120
118
|
this.cameras.forEach(function(camera) {
|
|
121
119
|
// render the root container
|
|
122
120
|
camera.draw(renderer, game.world);
|
|
123
121
|
});
|
|
124
|
-
}
|
|
122
|
+
}
|
|
125
123
|
|
|
126
124
|
/**
|
|
127
125
|
* destroy function
|
|
128
126
|
* @ignore
|
|
129
127
|
*/
|
|
130
|
-
destroy
|
|
128
|
+
destroy() {
|
|
131
129
|
// clear all cameras
|
|
132
130
|
this.cameras.clear();
|
|
133
131
|
// notify the object
|
|
134
132
|
this.onDestroyEvent.apply(this, arguments);
|
|
135
|
-
}
|
|
133
|
+
}
|
|
136
134
|
|
|
137
135
|
/**
|
|
138
136
|
* onResetEvent function<br>
|
|
@@ -144,13 +142,13 @@ var Stage = window.Jay.extend({
|
|
|
144
142
|
* @param {} [arguments...] optional arguments passed when switching state
|
|
145
143
|
* @see me.state#change
|
|
146
144
|
*/
|
|
147
|
-
onResetEvent
|
|
145
|
+
onResetEvent() {
|
|
148
146
|
// execute onResetEvent function if given through the constructor
|
|
149
147
|
if (typeof this.settings.onResetEvent === "function") {
|
|
150
148
|
this.settings.onResetEvent.apply(this, arguments);
|
|
151
149
|
}
|
|
152
150
|
|
|
153
|
-
}
|
|
151
|
+
}
|
|
154
152
|
|
|
155
153
|
/**
|
|
156
154
|
* onDestroyEvent function<br>
|
|
@@ -159,12 +157,12 @@ var Stage = window.Jay.extend({
|
|
|
159
157
|
* @memberOf me.Stage
|
|
160
158
|
* @function
|
|
161
159
|
*/
|
|
162
|
-
onDestroyEvent
|
|
160
|
+
onDestroyEvent() {
|
|
163
161
|
// execute onDestroyEvent function if given through the constructor
|
|
164
162
|
if (typeof this.settings.onDestroyEvent === "function") {
|
|
165
163
|
this.settings.onDestroyEvent.apply(this, arguments);
|
|
166
164
|
}
|
|
167
165
|
}
|
|
168
|
-
}
|
|
166
|
+
};
|
|
169
167
|
|
|
170
168
|
export default Stage;
|
package/src/state/state.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import event from "./../system/event.js";
|
|
1
|
+
import { pauseTrack, resumeTrack } from "./../audio/audio.js";
|
|
2
|
+
import * as fctUtil from "./../utils/function.js";
|
|
3
|
+
import * as event from "./../system/event.js";
|
|
4
4
|
import timer from "./../system/timer.js";
|
|
5
|
-
import game from "./../game.js";
|
|
5
|
+
import * as game from "./../game.js";
|
|
6
6
|
import Stage from "./../state/stage.js";
|
|
7
7
|
import defaultLoadingScreen from "./../loader/loadingscreen.js";
|
|
8
8
|
|
|
@@ -134,6 +134,18 @@ function _switchState(state) {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
// initialize me.state on system boot
|
|
138
|
+
event.on(event.BOOT, () => {
|
|
139
|
+
// set the built-in loading stage
|
|
140
|
+
state.set(state.LOADING, defaultLoadingScreen);
|
|
141
|
+
// set and enable the default stage
|
|
142
|
+
state.set(state.DEFAULT, new Stage());
|
|
143
|
+
// enable by default as soon as the display is initialized
|
|
144
|
+
event.on(event.VIDEO_INIT, () => {
|
|
145
|
+
state.change(state.DEFAULT, true);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
137
149
|
|
|
138
150
|
/**
|
|
139
151
|
* a State Manager (state machine)
|
|
@@ -237,53 +249,6 @@ var state = {
|
|
|
237
249
|
*/
|
|
238
250
|
USER : 100,
|
|
239
251
|
|
|
240
|
-
/**
|
|
241
|
-
* onPause callback
|
|
242
|
-
* @function
|
|
243
|
-
* @name onPause
|
|
244
|
-
* @memberOf me.state
|
|
245
|
-
*/
|
|
246
|
-
onPause : null,
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* onResume callback
|
|
250
|
-
* @function
|
|
251
|
-
* @name onResume
|
|
252
|
-
* @memberOf me.state
|
|
253
|
-
*/
|
|
254
|
-
onResume : null,
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* onStop callback
|
|
258
|
-
* @function
|
|
259
|
-
* @name onStop
|
|
260
|
-
* @memberOf me.state
|
|
261
|
-
*/
|
|
262
|
-
onStop : null,
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* onRestart callback
|
|
266
|
-
* @function
|
|
267
|
-
* @name onRestart
|
|
268
|
-
* @memberOf me.state
|
|
269
|
-
*/
|
|
270
|
-
onRestart : null,
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* @ignore
|
|
274
|
-
*/
|
|
275
|
-
init() {
|
|
276
|
-
// set the built-in loading stage
|
|
277
|
-
this.set(this.LOADING, defaultLoadingScreen);
|
|
278
|
-
// set and enable the default stage
|
|
279
|
-
this.set(this.DEFAULT, new Stage());
|
|
280
|
-
// enable by default as soon as the display is initialized
|
|
281
|
-
var _state = this;
|
|
282
|
-
event.subscribe(event.VIDEO_INIT, function () {
|
|
283
|
-
_state.change(_state.DEFAULT, true);
|
|
284
|
-
});
|
|
285
|
-
},
|
|
286
|
-
|
|
287
252
|
/**
|
|
288
253
|
* Stop the current screen object.
|
|
289
254
|
* @name stop
|
|
@@ -299,18 +264,14 @@ var state = {
|
|
|
299
264
|
_stopRunLoop();
|
|
300
265
|
// current music stop
|
|
301
266
|
if (music === true) {
|
|
302
|
-
|
|
267
|
+
pauseTrack();
|
|
303
268
|
}
|
|
304
269
|
|
|
305
270
|
// store time when stopped
|
|
306
271
|
_pauseTime = window.performance.now();
|
|
307
272
|
|
|
308
273
|
// publish the stop notification
|
|
309
|
-
event.
|
|
310
|
-
// any callback defined ?
|
|
311
|
-
if (typeof(this.onStop) === "function") {
|
|
312
|
-
this.onStop();
|
|
313
|
-
}
|
|
274
|
+
event.emit(event.STATE_STOP);
|
|
314
275
|
}
|
|
315
276
|
},
|
|
316
277
|
|
|
@@ -329,18 +290,14 @@ var state = {
|
|
|
329
290
|
_pauseRunLoop();
|
|
330
291
|
// current music stop
|
|
331
292
|
if (music === true) {
|
|
332
|
-
|
|
293
|
+
pauseTrack();
|
|
333
294
|
}
|
|
334
295
|
|
|
335
296
|
// store time when paused
|
|
336
297
|
_pauseTime = window.performance.now();
|
|
337
298
|
|
|
338
299
|
// publish the pause event
|
|
339
|
-
event.
|
|
340
|
-
// any callback defined ?
|
|
341
|
-
if (typeof(this.onPause) === "function") {
|
|
342
|
-
this.onPause();
|
|
343
|
-
}
|
|
300
|
+
event.emit(event.STATE_PAUSE);
|
|
344
301
|
}
|
|
345
302
|
},
|
|
346
303
|
|
|
@@ -358,7 +315,7 @@ var state = {
|
|
|
358
315
|
_startRunLoop();
|
|
359
316
|
// current music stop
|
|
360
317
|
if (music === true) {
|
|
361
|
-
|
|
318
|
+
resumeTrack();
|
|
362
319
|
}
|
|
363
320
|
|
|
364
321
|
// calculate the elpased time
|
|
@@ -368,11 +325,7 @@ var state = {
|
|
|
368
325
|
game.repaint();
|
|
369
326
|
|
|
370
327
|
// publish the restart notification
|
|
371
|
-
event.
|
|
372
|
-
// any callback defined ?
|
|
373
|
-
if (typeof(this.onRestart) === "function") {
|
|
374
|
-
this.onRestart();
|
|
375
|
-
}
|
|
328
|
+
event.emit(event.STATE_RESTART, _pauseTime);
|
|
376
329
|
}
|
|
377
330
|
},
|
|
378
331
|
|
|
@@ -390,18 +343,14 @@ var state = {
|
|
|
390
343
|
_resumeRunLoop();
|
|
391
344
|
// current music stop
|
|
392
345
|
if (music === true) {
|
|
393
|
-
|
|
346
|
+
resumeTrack();
|
|
394
347
|
}
|
|
395
348
|
|
|
396
349
|
// calculate the elpased time
|
|
397
350
|
_pauseTime = window.performance.now() - _pauseTime;
|
|
398
351
|
|
|
399
352
|
// publish the resume event
|
|
400
|
-
event.
|
|
401
|
-
// any callback defined ?
|
|
402
|
-
if (typeof(this.onResume) === "function") {
|
|
403
|
-
this.onResume();
|
|
404
|
-
}
|
|
353
|
+
event.emit(event.STATE_RESUME, _pauseTime);
|
|
405
354
|
}
|
|
406
355
|
},
|
|
407
356
|
|
|
@@ -439,16 +388,16 @@ var state = {
|
|
|
439
388
|
* @param {me.Stage} stage Instantiated Stage to associate with state ID
|
|
440
389
|
* @param {Boolean} [start = false] if true the state will be changed immediately after adding it.
|
|
441
390
|
* @example
|
|
442
|
-
*
|
|
443
|
-
*
|
|
391
|
+
* class MenuButton extends me.GUI_Object {
|
|
392
|
+
* onClick() {
|
|
444
393
|
* // Change to the PLAY state when the button is clicked
|
|
445
394
|
* me.state.change(me.state.PLAY);
|
|
446
395
|
* return true;
|
|
447
396
|
* }
|
|
448
|
-
* }
|
|
397
|
+
* };
|
|
449
398
|
*
|
|
450
|
-
*
|
|
451
|
-
* onResetEvent
|
|
399
|
+
* class MenuScreen extends me.Stage {
|
|
400
|
+
* onResetEvent() {
|
|
452
401
|
* // Load background image
|
|
453
402
|
* me.game.world.addChild(
|
|
454
403
|
* new me.ImageLayer(0, 0, {
|
|
@@ -465,17 +414,17 @@ var state = {
|
|
|
465
414
|
*
|
|
466
415
|
* // Play music
|
|
467
416
|
* me.audio.playTrack("menu");
|
|
468
|
-
* }
|
|
417
|
+
* }
|
|
469
418
|
*
|
|
470
|
-
*
|
|
419
|
+
* onDestroyEvent() {
|
|
471
420
|
* // Stop music
|
|
472
421
|
* me.audio.stopTrack();
|
|
473
422
|
* }
|
|
474
|
-
* }
|
|
423
|
+
* };
|
|
475
424
|
*
|
|
476
425
|
* me.state.set(me.state.MENU, new MenuScreen());
|
|
477
426
|
*/
|
|
478
|
-
set(state, stage, start) {
|
|
427
|
+
set(state, stage, start = false) {
|
|
479
428
|
if (!(stage instanceof Stage)) {
|
|
480
429
|
throw new Error(stage + " is not an instance of me.Stage");
|
|
481
430
|
}
|
|
@@ -573,7 +522,7 @@ var state = {
|
|
|
573
522
|
_fade.color,
|
|
574
523
|
_fade.duration,
|
|
575
524
|
function () {
|
|
576
|
-
|
|
525
|
+
fctUtil.defer(_switchState, this, state);
|
|
577
526
|
}
|
|
578
527
|
);
|
|
579
528
|
|
|
@@ -585,7 +534,7 @@ var state = {
|
|
|
585
534
|
if (forceChange === true) {
|
|
586
535
|
_switchState(state);
|
|
587
536
|
} else {
|
|
588
|
-
|
|
537
|
+
fctUtil.defer(_switchState, this, state);
|
|
589
538
|
}
|
|
590
539
|
}
|
|
591
540
|
},
|