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/system/event.js
CHANGED
|
@@ -1,441 +1,494 @@
|
|
|
1
|
-
|
|
2
|
-
import MinPubSub from "minpubsub";
|
|
1
|
+
import EventEmitter from "eventemitter3";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
|
-
* an event system based on
|
|
4
|
+
* an event system based on nodeJS EventEmitter interface
|
|
6
5
|
* @namespace event
|
|
7
6
|
* @memberOf me
|
|
8
7
|
*/
|
|
9
|
-
var event = {
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Channel Constant when the game is paused <br>
|
|
13
|
-
* Data passed : none <br>
|
|
14
|
-
* @public
|
|
15
|
-
* @constant
|
|
16
|
-
* @type String
|
|
17
|
-
* @name STATE_PAUSE
|
|
18
|
-
* @memberOf me.event
|
|
19
|
-
* @see me.event.subscribe
|
|
20
|
-
*/
|
|
21
|
-
STATE_PAUSE : "me.state.onPause",
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Channel Constant for when the game is resumed <br>
|
|
25
|
-
* Data passed : {Number} time in ms the game was paused
|
|
26
|
-
* @public
|
|
27
|
-
* @constant
|
|
28
|
-
* @type String
|
|
29
|
-
* @name STATE_RESUME
|
|
30
|
-
* @memberOf me.event
|
|
31
|
-
* @see me.event.subscribe
|
|
32
|
-
*/
|
|
33
|
-
STATE_RESUME : "me.state.onResume",
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Channel Constant when the game is stopped <br>
|
|
37
|
-
* Data passed : none <br>
|
|
38
|
-
* @public
|
|
39
|
-
* @constant
|
|
40
|
-
* @type String
|
|
41
|
-
* @name STATE_STOP
|
|
42
|
-
* @memberOf me.event
|
|
43
|
-
* @see me.event.subscribe
|
|
44
|
-
*/
|
|
45
|
-
STATE_STOP : "me.state.onStop",
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Channel Constant for when the game is restarted <br>
|
|
49
|
-
* Data passed : {Number} time in ms the game was stopped
|
|
50
|
-
* @public
|
|
51
|
-
* @constant
|
|
52
|
-
* @type String
|
|
53
|
-
* @name STATE_RESTART
|
|
54
|
-
* @memberOf me.event
|
|
55
|
-
* @see me.event.subscribe
|
|
56
|
-
*/
|
|
57
|
-
STATE_RESTART : "me.state.onRestart",
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Channel Constant for when the video is initialized<br>
|
|
61
|
-
* Data passed : none <br>
|
|
62
|
-
* @public
|
|
63
|
-
* @constant
|
|
64
|
-
* @type String
|
|
65
|
-
* @name VIDEO_INIT
|
|
66
|
-
* @memberOf me.event
|
|
67
|
-
* @see me.video.init
|
|
68
|
-
* @see me.event.subscribe
|
|
69
|
-
*/
|
|
70
|
-
VIDEO_INIT : "me.video.onInit",
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Channel Constant for when the game manager is initialized <br>
|
|
75
|
-
* Data passed : none <br>
|
|
76
|
-
* @public
|
|
77
|
-
* @constant
|
|
78
|
-
* @type String
|
|
79
|
-
* @name GAME_INIT
|
|
80
|
-
* @memberOf me.event
|
|
81
|
-
* @see me.event.subscribe
|
|
82
|
-
*/
|
|
83
|
-
GAME_INIT : "me.game.onInit",
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Channel Constant for when the game manager is resetted <br>
|
|
87
|
-
* Data passed : none <br>
|
|
88
|
-
* @public
|
|
89
|
-
* @constant
|
|
90
|
-
* @type String
|
|
91
|
-
* @name GAME_RESET
|
|
92
|
-
* @memberOf me.event
|
|
93
|
-
* @see me.event.subscribe
|
|
94
|
-
*/
|
|
95
|
-
GAME_RESET : "me.game.onReset",
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Channel Constant for when the game manager is updated (start of the update loop) <br>
|
|
99
|
-
* Data passed : {Number} time the current time stamp
|
|
100
|
-
* @public
|
|
101
|
-
* @constant
|
|
102
|
-
* @type String
|
|
103
|
-
* @name GAME_UPDATE
|
|
104
|
-
* @memberOf me.event
|
|
105
|
-
* @see me.event.subscribe
|
|
106
|
-
*/
|
|
107
|
-
GAME_UPDATE : "me.game.onUpdate",
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Channel Constant for when a level is loaded <br>
|
|
111
|
-
* Data passed : {String} Level Name
|
|
112
|
-
* @public
|
|
113
|
-
* @constant
|
|
114
|
-
* @type String
|
|
115
|
-
* @name LEVEL_LOADED
|
|
116
|
-
* @memberOf me.event
|
|
117
|
-
* @see me.event.subscribe
|
|
118
|
-
*/
|
|
119
|
-
LEVEL_LOADED : "me.game.onLevelLoaded",
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Channel Constant for when everything has loaded <br>
|
|
123
|
-
* Data passed : none <br>
|
|
124
|
-
* @public
|
|
125
|
-
* @constant
|
|
126
|
-
* @type String
|
|
127
|
-
* @name LOADER_COMPLETE
|
|
128
|
-
* @memberOf me.event
|
|
129
|
-
* @see me.event.subscribe
|
|
130
|
-
*/
|
|
131
|
-
LOADER_COMPLETE : "me.loader.onload",
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Channel Constant for displaying a load progress indicator <br>
|
|
135
|
-
* Data passed : {Number} [0 .. 1], {Resource} resource object<br>
|
|
136
|
-
* @public
|
|
137
|
-
* @constant
|
|
138
|
-
* @type String
|
|
139
|
-
* @name LOADER_PROGRESS
|
|
140
|
-
* @memberOf me.event
|
|
141
|
-
* @see me.event.subscribe
|
|
142
|
-
*/
|
|
143
|
-
LOADER_PROGRESS : "me.loader.onProgress",
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Channel Constant for pressing a binded key <br>
|
|
147
|
-
* Data passed : {String} user-defined action, {Number} keyCode,
|
|
148
|
-
* {Boolean} edge state <br>
|
|
149
|
-
* Edge-state is for detecting "locked" key bindings. When a locked key
|
|
150
|
-
* is pressed and held, the first event will have the third argument
|
|
151
|
-
* set true. Subsequent events will continue firing with the third
|
|
152
|
-
* argument set false.
|
|
153
|
-
* @public
|
|
154
|
-
* @constant
|
|
155
|
-
* @type String
|
|
156
|
-
* @name KEYDOWN
|
|
157
|
-
* @memberOf me.event
|
|
158
|
-
* @see me.event.subscribe
|
|
159
|
-
* @example
|
|
160
|
-
* me.input.bindKey(me.input.KEY.X, "jump", true); // Edge-triggered
|
|
161
|
-
* me.input.bindKey(me.input.KEY.Z, "shoot"); // Level-triggered
|
|
162
|
-
* me.event.subscribe(me.event.KEYDOWN, function (action, keyCode, edge) {
|
|
163
|
-
* // Checking bound keys
|
|
164
|
-
* if (action === "jump") {
|
|
165
|
-
* if (edge) {
|
|
166
|
-
* this.doJump();
|
|
167
|
-
* }
|
|
168
|
-
*
|
|
169
|
-
* // Make character fall slower when holding the jump key
|
|
170
|
-
* this.vel.y = this.body.gravity;
|
|
171
|
-
* }
|
|
172
|
-
* });
|
|
173
|
-
*/
|
|
174
|
-
KEYDOWN : "me.input.keydown",
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Channel Constant for releasing a binded key <br>
|
|
178
|
-
* Data passed : {String} user-defined action, {Number} keyCode
|
|
179
|
-
* @public
|
|
180
|
-
* @constant
|
|
181
|
-
* @type String
|
|
182
|
-
* @name KEYUP
|
|
183
|
-
* @memberOf me.event
|
|
184
|
-
* @see me.event.subscribe
|
|
185
|
-
* @example
|
|
186
|
-
* me.event.subscribe(me.event.KEYUP, function (action, keyCode) {
|
|
187
|
-
* // Checking unbound keys
|
|
188
|
-
* if (keyCode == me.input.KEY.ESC) {
|
|
189
|
-
* if (me.state.isPaused()) {
|
|
190
|
-
* me.state.resume();
|
|
191
|
-
* }
|
|
192
|
-
* else {
|
|
193
|
-
* me.state.pause();
|
|
194
|
-
* }
|
|
195
|
-
* }
|
|
196
|
-
* });
|
|
197
|
-
*/
|
|
198
|
-
KEYUP : "me.input.keyup",
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Channel Constant for when a gamepad is connected <br>
|
|
202
|
-
* Data passed : {Object} gamepad object
|
|
203
|
-
* @public
|
|
204
|
-
* @constant
|
|
205
|
-
* @type String
|
|
206
|
-
* @name GAMEPAD_CONNECTED
|
|
207
|
-
* @memberOf me.event
|
|
208
|
-
* @see me.event.subscribe
|
|
209
|
-
*/
|
|
210
|
-
GAMEPAD_CONNECTED : "gamepad.connected",
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Channel Constant for when a gamepad is disconnected <br>
|
|
214
|
-
* Data passed : {Object} gamepad object
|
|
215
|
-
* @public
|
|
216
|
-
* @constant
|
|
217
|
-
* @type String
|
|
218
|
-
* @name GAMEPAD_DISCONNECTED
|
|
219
|
-
* @memberOf me.event
|
|
220
|
-
* @see me.event.subscribe
|
|
221
|
-
*/
|
|
222
|
-
GAMEPAD_DISCONNECTED : "gamepad.disconnected",
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Channel Constant for when gamepad button/axis state is updated <br>
|
|
226
|
-
* Data passed : {Number} index <br>
|
|
227
|
-
* Data passed : {String} type : "axes" or "buttons" <br>
|
|
228
|
-
* Data passed : {Number} button <br>
|
|
229
|
-
* Data passed : {Number} current.value <br>
|
|
230
|
-
* Data passed : {Boolean} current.pressed
|
|
231
|
-
* @public
|
|
232
|
-
* @constant
|
|
233
|
-
* @type String
|
|
234
|
-
* @name GAMEPAD_UPDATE
|
|
235
|
-
* @memberOf me.event
|
|
236
|
-
* @see me.event.subscribe
|
|
237
|
-
*/
|
|
238
|
-
GAMEPAD_UPDATE : "gamepad.update",
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Channel Constant for pointermove events on the screen area <br>
|
|
242
|
-
* Data passed : {me.Pointer} a Pointer object
|
|
243
|
-
* @public
|
|
244
|
-
* @constant
|
|
245
|
-
* @type String
|
|
246
|
-
* @name POINTERMOVE
|
|
247
|
-
* @memberOf me.event
|
|
248
|
-
* @see me.event.subscribe
|
|
249
|
-
*/
|
|
250
|
-
POINTERMOVE : "me.event.pointermove",
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Channel Constant for dragstart events on a Draggable entity <br>
|
|
254
|
-
* Data passed:
|
|
255
|
-
* {Object} the drag event <br>
|
|
256
|
-
* {Object} the Draggable entity
|
|
257
|
-
* @public
|
|
258
|
-
* @constant
|
|
259
|
-
* @type String
|
|
260
|
-
* @name DRAGSTART
|
|
261
|
-
* @memberOf me.event
|
|
262
|
-
* @see me.event.subscribe
|
|
263
|
-
*/
|
|
264
|
-
DRAGSTART : "me.game.dragstart",
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Channel Constant for dragend events on a Draggable entity <br>
|
|
268
|
-
* Data passed:
|
|
269
|
-
* {Object} the drag event <br>
|
|
270
|
-
* {Object} the Draggable entity
|
|
271
|
-
* @public
|
|
272
|
-
* @constant
|
|
273
|
-
* @type String
|
|
274
|
-
* @name DRAGEND
|
|
275
|
-
* @memberOf me.event
|
|
276
|
-
* @see me.event.subscribe
|
|
277
|
-
*/
|
|
278
|
-
DRAGEND : "me.game.dragend",
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Channel Constant for when the (browser) window is resized <br>
|
|
282
|
-
* Data passed : {Event} Event object
|
|
283
|
-
* @public
|
|
284
|
-
* @constant
|
|
285
|
-
* @type String
|
|
286
|
-
* @name WINDOW_ONRESIZE
|
|
287
|
-
* @memberOf me.event
|
|
288
|
-
* @see me.event.subscribe
|
|
289
|
-
*/
|
|
290
|
-
WINDOW_ONRESIZE : "window.onresize",
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Channel Constant for when the canvas is resized <br>
|
|
294
|
-
* (this usually follows a WINDOW_ONRESIZE event).<br>
|
|
295
|
-
* Data passed : {Number} canvas width <br>
|
|
296
|
-
* Data passed : {Number} canvas height
|
|
297
|
-
* @public
|
|
298
|
-
* @constant
|
|
299
|
-
* @type String
|
|
300
|
-
* @name CANVAS_ONRESIZE
|
|
301
|
-
* @memberOf me.event
|
|
302
|
-
* @see me.event.subscribe
|
|
303
|
-
*/
|
|
304
|
-
CANVAS_ONRESIZE : "canvas.onresize",
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Channel Constant for when the viewport is resized <br>
|
|
308
|
-
* (this usually follows a WINDOW_ONRESIZE event, when using the `flex` scaling mode is used and after the viewport was updated).<br>
|
|
309
|
-
* Data passed : {Number} viewport width <br>
|
|
310
|
-
* Data passed : {Number} viewport height
|
|
311
|
-
* @public
|
|
312
|
-
* @constant
|
|
313
|
-
* @type String
|
|
314
|
-
* @name VIEWPORT_ONRESIZE
|
|
315
|
-
* @memberOf me.event
|
|
316
|
-
* @see me.event.subscribe
|
|
317
|
-
*/
|
|
318
|
-
VIEWPORT_ONRESIZE : "viewport.onresize",
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Channel Constant for when the device is rotated <br>
|
|
322
|
-
* Data passed : {Event} Event object <br>
|
|
323
|
-
* @public
|
|
324
|
-
* @constant
|
|
325
|
-
* @type String
|
|
326
|
-
* @name WINDOW_ONORIENTATION_CHANGE
|
|
327
|
-
* @memberOf me.event
|
|
328
|
-
* @see me.event.subscribe
|
|
329
|
-
*/
|
|
330
|
-
WINDOW_ONORIENTATION_CHANGE : "window.orientationchange",
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Channel Constant for when the (browser) window is scrolled <br>
|
|
334
|
-
* Data passed : {Event} Event object
|
|
335
|
-
* @public
|
|
336
|
-
* @constant
|
|
337
|
-
* @type String
|
|
338
|
-
* @name WINDOW_ONSCROLL
|
|
339
|
-
* @memberOf me.event
|
|
340
|
-
* @see me.event.subscribe
|
|
341
|
-
*/
|
|
342
|
-
WINDOW_ONSCROLL : "window.onscroll",
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Channel Constant for when the viewport position is updated <br>
|
|
346
|
-
* Data passed : {me.Vector2d} viewport position vector
|
|
347
|
-
* @public
|
|
348
|
-
* @constant
|
|
349
|
-
* @type String
|
|
350
|
-
* @name VIEWPORT_ONCHANGE
|
|
351
|
-
* @memberOf me.event
|
|
352
|
-
* @see me.event.subscribe
|
|
353
|
-
*/
|
|
354
|
-
VIEWPORT_ONCHANGE : "viewport.onchange",
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Channel Constant for when WebGL context is lost <br>
|
|
358
|
-
* Data passed : {me.WebGLRenderer} the current webgl renderer instance`
|
|
359
|
-
* @public
|
|
360
|
-
* @constant
|
|
361
|
-
* @type String
|
|
362
|
-
* @name WEBGL_ONCONTEXT_LOST
|
|
363
|
-
* @memberOf me.event
|
|
364
|
-
* @see me.event.subscribe
|
|
365
|
-
*/
|
|
366
|
-
WEBGL_ONCONTEXT_LOST : "renderer.webglcontextlost",
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Channel Constant for when WebGL context is restored <br>
|
|
370
|
-
* Data passed : {me.WebGLRenderer} the current webgl renderer instance`
|
|
371
|
-
* @public
|
|
372
|
-
* @constant
|
|
373
|
-
* @type String
|
|
374
|
-
* @name WEBGL_ONCONTEXT_RESTORED
|
|
375
|
-
* @memberOf me.event
|
|
376
|
-
* @see me.event.subscribe
|
|
377
|
-
*/
|
|
378
|
-
WEBGL_ONCONTEXT_RESTORED : "renderer.webglcontextrestored",
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Publish some data on a channel
|
|
382
|
-
* @name publish
|
|
383
|
-
* @memberOf me.event
|
|
384
|
-
* @public
|
|
385
|
-
* @function
|
|
386
|
-
* @param {String} channel The channel to publish on
|
|
387
|
-
* @param {Array} arguments The data to publish
|
|
388
|
-
*
|
|
389
|
-
* @example Publish stuff on '/some/channel'.
|
|
390
|
-
* Anything subscribed will be called with a function
|
|
391
|
-
* signature like: function (a,b,c){ ... }
|
|
392
|
-
*
|
|
393
|
-
* me.event.publish("/some/channel", ["a","b","c"]);
|
|
394
|
-
*
|
|
395
|
-
*/
|
|
396
|
-
publish : MinPubSub.publish,
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Register a callback on a named channel.
|
|
400
|
-
* @name subscribe
|
|
401
|
-
* @memberOf me.event
|
|
402
|
-
* @public
|
|
403
|
-
* @function
|
|
404
|
-
* @param {String} channel The channel to subscribe to
|
|
405
|
-
* @param {Function} callback The event handler, any time something is
|
|
406
|
-
* published on a subscribed channel, the callback will be called
|
|
407
|
-
* with the published array as ordered arguments
|
|
408
|
-
* @return {handle} A handle which can be used to unsubscribe this
|
|
409
|
-
* particular subscription
|
|
410
|
-
* @example
|
|
411
|
-
* me.event.subscribe("/some/channel", function (a, b, c){ doSomething(); });
|
|
412
|
-
*/
|
|
413
|
-
|
|
414
|
-
subscribe : MinPubSub.subscribe,
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Disconnect a subscribed function for a channel.
|
|
418
|
-
* @name unsubscribe
|
|
419
|
-
* @memberOf me.event
|
|
420
|
-
* @see me.event.subscribe
|
|
421
|
-
* @public
|
|
422
|
-
* @function
|
|
423
|
-
* @param {Array|String} handle The return value from a subscribe call or the
|
|
424
|
-
* name of a channel as a String
|
|
425
|
-
* @param {Function} [callback] The callback to be unsubscribed.
|
|
426
|
-
* @example
|
|
427
|
-
* var handle = me.event.subscribe("/some/channel", function (){});
|
|
428
|
-
* me.event.unsubscribe(handle);
|
|
429
|
-
*
|
|
430
|
-
* // Or alternatively ...
|
|
431
|
-
*
|
|
432
|
-
* var callback = function (){};
|
|
433
|
-
* me.event.subscribe("/some/channel", callback);
|
|
434
|
-
* me.event.unsubscribe("/some/channel", callback);
|
|
435
|
-
*/
|
|
436
|
-
unsubscribe : MinPubSub.unsubscribe
|
|
437
8
|
|
|
9
|
+
// internal instance of the event emiter
|
|
10
|
+
var eventEmitter = new EventEmitter();
|
|
438
11
|
|
|
12
|
+
/**
|
|
13
|
+
* event when the system is booting
|
|
14
|
+
* @public
|
|
15
|
+
* @constant
|
|
16
|
+
* @type String
|
|
17
|
+
* @name BOOT
|
|
18
|
+
* @memberOf me.event
|
|
19
|
+
* @see me.event.on
|
|
20
|
+
*/
|
|
21
|
+
export const BOOT = "me.boot";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* event when the game is paused <br>
|
|
25
|
+
* Data passed : none <br>
|
|
26
|
+
* @public
|
|
27
|
+
* @constant
|
|
28
|
+
* @type String
|
|
29
|
+
* @name STATE_PAUSE
|
|
30
|
+
* @memberOf me.event
|
|
31
|
+
* @see me.event.on
|
|
32
|
+
*/
|
|
33
|
+
export const STATE_PAUSE = "me.state.onPause";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* event for when the game is resumed <br>
|
|
37
|
+
* Data passed : {Number} time in ms the game was paused
|
|
38
|
+
* @public
|
|
39
|
+
* @constant
|
|
40
|
+
* @type String
|
|
41
|
+
* @name STATE_RESUME
|
|
42
|
+
* @memberOf me.event
|
|
43
|
+
* @see me.event.on
|
|
44
|
+
*/
|
|
45
|
+
export const STATE_RESUME = "me.state.onResume";
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* event when the game is stopped <br>
|
|
49
|
+
* Data passed : none <br>
|
|
50
|
+
* @public
|
|
51
|
+
* @constant
|
|
52
|
+
* @type String
|
|
53
|
+
* @name STATE_STOP
|
|
54
|
+
* @memberOf me.event
|
|
55
|
+
* @see me.event.on
|
|
56
|
+
*/
|
|
57
|
+
export const STATE_STOP = "me.state.onStop";
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* event for when the game is restarted <br>
|
|
61
|
+
* Data passed : {Number} time in ms the game was stopped
|
|
62
|
+
* @public
|
|
63
|
+
* @constant
|
|
64
|
+
* @type String
|
|
65
|
+
* @name STATE_RESTART
|
|
66
|
+
* @memberOf me.event
|
|
67
|
+
* @see me.event.on
|
|
68
|
+
*/
|
|
69
|
+
export const STATE_RESTART = "me.state.onRestart";
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* event for when the video is initialized<br>
|
|
73
|
+
* Data passed : none <br>
|
|
74
|
+
* @public
|
|
75
|
+
* @constant
|
|
76
|
+
* @type String
|
|
77
|
+
* @name VIDEO_INIT
|
|
78
|
+
* @memberOf me.event
|
|
79
|
+
* @see me.video.init
|
|
80
|
+
* @see me.event.on
|
|
81
|
+
*/
|
|
82
|
+
export const VIDEO_INIT = "me.video.onInit";
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* event for when the game manager is initialized <br>
|
|
86
|
+
* Data passed : none <br>
|
|
87
|
+
* @public
|
|
88
|
+
* @constant
|
|
89
|
+
* @type String
|
|
90
|
+
* @name GAME_INIT
|
|
91
|
+
* @memberOf me.event
|
|
92
|
+
* @see me.event.on
|
|
93
|
+
*/
|
|
94
|
+
export const GAME_INIT = "me.game.onInit";
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* event for when the game manager is resetted <br>
|
|
98
|
+
* Data passed : none <br>
|
|
99
|
+
* @public
|
|
100
|
+
* @constant
|
|
101
|
+
* @type String
|
|
102
|
+
* @name GAME_RESET
|
|
103
|
+
* @memberOf me.event
|
|
104
|
+
* @see me.event.on
|
|
105
|
+
*/
|
|
106
|
+
export const GAME_RESET = "me.game.onReset";
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* event for when the engine is about to start a new game loop
|
|
110
|
+
* Data passed : {Number} time the current time stamp
|
|
111
|
+
* @public
|
|
112
|
+
* @constant
|
|
113
|
+
* @type String
|
|
114
|
+
* @name GAME_BEFORE_UPDATE
|
|
115
|
+
* @memberOf me.event
|
|
116
|
+
* @see me.event.on
|
|
117
|
+
*/
|
|
118
|
+
export const GAME_BEFORE_UPDATE = "me.game.beforeUpdate";
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* event for the end of the update loop
|
|
122
|
+
* Data passed : {Number} time the current time stamp
|
|
123
|
+
* @public
|
|
124
|
+
* @constant
|
|
125
|
+
* @type String
|
|
126
|
+
* @name GAME_AFTER_UPDATE
|
|
127
|
+
* @memberOf me.event
|
|
128
|
+
* @see me.event.on
|
|
129
|
+
*/
|
|
130
|
+
export const GAME_AFTER_UPDATE = "me.game.afterUpdate";
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Event for when the game is updated (will be impacted by frame skip, frame interpolation and pause/resume state) <br>
|
|
134
|
+
* Data passed : {Number} time the current time stamp
|
|
135
|
+
* @public
|
|
136
|
+
* @constant
|
|
137
|
+
* @type String
|
|
138
|
+
* @name GAME_UPDATE
|
|
139
|
+
* @memberOf me.event
|
|
140
|
+
* @see me.event.on
|
|
141
|
+
*/
|
|
142
|
+
export const GAME_UPDATE = "me.game.onUpdate";
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Event for the end of the draw loop
|
|
146
|
+
* Data passed : {Number} time the current time stamp
|
|
147
|
+
* @public
|
|
148
|
+
* @constant
|
|
149
|
+
* @type String
|
|
150
|
+
* @name GAME_BEFORE_DRAW
|
|
151
|
+
* @memberOf me.event
|
|
152
|
+
* @see me.event.on
|
|
153
|
+
*/
|
|
154
|
+
export const GAME_BEFORE_DRAW = "me.game.beforeDraw";
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Event for the start of the draw loop
|
|
158
|
+
* Data passed : {Number} time the current time stamp
|
|
159
|
+
* @public
|
|
160
|
+
* @constant
|
|
161
|
+
* @type String
|
|
162
|
+
* @name GAME_AFTER_DRAW
|
|
163
|
+
* @memberOf me.event
|
|
164
|
+
* @see me.event.on
|
|
165
|
+
*/
|
|
166
|
+
export const GAME_AFTER_DRAW = "me.game.afterDraw";
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Event for when a level is loaded <br>
|
|
170
|
+
* Data passed : {String} Level Name
|
|
171
|
+
* @public
|
|
172
|
+
* @constant
|
|
173
|
+
* @type String
|
|
174
|
+
* @name LEVEL_LOADED
|
|
175
|
+
* @memberOf me.event
|
|
176
|
+
* @see me.event.on
|
|
177
|
+
*/
|
|
178
|
+
export const LEVEL_LOADED = "me.game.onLevelLoaded";
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Event for when everything has loaded <br>
|
|
182
|
+
* Data passed : none <br>
|
|
183
|
+
* @public
|
|
184
|
+
* @constant
|
|
185
|
+
* @type String
|
|
186
|
+
* @name LOADER_COMPLETE
|
|
187
|
+
* @memberOf me.event
|
|
188
|
+
* @see me.event.on
|
|
189
|
+
*/
|
|
190
|
+
export const LOADER_COMPLETE = "me.loader.onload";
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Event for displaying a load progress indicator <br>
|
|
194
|
+
* Data passed : {Number} [0 .. 1], {Resource} resource object<br>
|
|
195
|
+
* @public
|
|
196
|
+
* @constant
|
|
197
|
+
* @type String
|
|
198
|
+
* @name LOADER_PROGRESS
|
|
199
|
+
* @memberOf me.event
|
|
200
|
+
* @see me.event.on
|
|
201
|
+
*/
|
|
202
|
+
export const LOADER_PROGRESS = "me.loader.onProgress";
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Event for pressing a binded key <br>
|
|
206
|
+
* Data passed : {String} user-defined action, {Number} keyCode,
|
|
207
|
+
* {Boolean} edge state <br>
|
|
208
|
+
* Edge-state is for detecting "locked" key bindings. When a locked key
|
|
209
|
+
* is pressed and held, the first event will have the third argument
|
|
210
|
+
* set true. Subsequent events will continue firing with the third
|
|
211
|
+
* argument set false.
|
|
212
|
+
* @public
|
|
213
|
+
* @constant
|
|
214
|
+
* @type String
|
|
215
|
+
* @name KEYDOWN
|
|
216
|
+
* @memberOf me.event
|
|
217
|
+
* @see me.event.on
|
|
218
|
+
* @example
|
|
219
|
+
* me.input.bindKey(me.input.KEY.X, "jump", true); // Edge-triggered
|
|
220
|
+
* me.input.bindKey(me.input.KEY.Z, "shoot"); // Level-triggered
|
|
221
|
+
* me.event.on(me.event.KEYDOWN, (action, keyCode, edge) => {
|
|
222
|
+
* // Checking bound keys
|
|
223
|
+
* if (action === "jump") {
|
|
224
|
+
* if (edge) {
|
|
225
|
+
* this.doJump();
|
|
226
|
+
* }
|
|
227
|
+
*
|
|
228
|
+
* // Make character fall slower when holding the jump key
|
|
229
|
+
* this.vel.y = this.body.gravity;
|
|
230
|
+
* }
|
|
231
|
+
* });
|
|
232
|
+
*/
|
|
233
|
+
export const KEYDOWN = "me.input.keydown";
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Event for releasing a binded key <br>
|
|
237
|
+
* Data passed : {String} user-defined action, {Number} keyCode
|
|
238
|
+
* @public
|
|
239
|
+
* @constant
|
|
240
|
+
* @type String
|
|
241
|
+
* @name KEYUP
|
|
242
|
+
* @memberOf me.event
|
|
243
|
+
* @see me.event.on
|
|
244
|
+
* @example
|
|
245
|
+
* me.event.on(me.event.KEYUP, (action, keyCode) => {
|
|
246
|
+
* // Checking unbound keys
|
|
247
|
+
* if (keyCode == me.input.KEY.ESC) {
|
|
248
|
+
* if (me.state.isPaused()) {
|
|
249
|
+
* me.state.resume();
|
|
250
|
+
* }
|
|
251
|
+
* else {
|
|
252
|
+
* me.state.pause();
|
|
253
|
+
* }
|
|
254
|
+
* }
|
|
255
|
+
* });
|
|
256
|
+
*/
|
|
257
|
+
export const KEYUP = "me.input.keyup";
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Event for when a gamepad is connected <br>
|
|
261
|
+
* Data passed : {Object} gamepad object
|
|
262
|
+
* @public
|
|
263
|
+
* @constant
|
|
264
|
+
* @type String
|
|
265
|
+
* @name GAMEPAD_CONNECTED
|
|
266
|
+
* @memberOf me.event
|
|
267
|
+
* @see me.event.on
|
|
268
|
+
*/
|
|
269
|
+
export const GAMEPAD_CONNECTED = "gamepad.connected";
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Event for when a gamepad is disconnected <br>
|
|
273
|
+
* Data passed : {Object} gamepad object
|
|
274
|
+
* @public
|
|
275
|
+
* @constant
|
|
276
|
+
* @type String
|
|
277
|
+
* @name GAMEPAD_DISCONNECTED
|
|
278
|
+
* @memberOf me.event
|
|
279
|
+
* @see me.event.on
|
|
280
|
+
*/
|
|
281
|
+
export const GAMEPAD_DISCONNECTED = "gamepad.disconnected";
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Event for when gamepad button/axis state is updated <br>
|
|
285
|
+
* Data passed : {Number} index <br>
|
|
286
|
+
* Data passed : {String} type : "axes" or "buttons" <br>
|
|
287
|
+
* Data passed : {Number} button <br>
|
|
288
|
+
* Data passed : {Number} current.value <br>
|
|
289
|
+
* Data passed : {Boolean} current.pressed
|
|
290
|
+
* @public
|
|
291
|
+
* @constant
|
|
292
|
+
* @type String
|
|
293
|
+
* @name GAMEPAD_UPDATE
|
|
294
|
+
* @memberOf me.event
|
|
295
|
+
* @see me.event.on
|
|
296
|
+
*/
|
|
297
|
+
export const GAMEPAD_UPDATE = "gamepad.update";
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Event for pointermove events on the screen area <br>
|
|
301
|
+
* Data passed : {me.Pointer} a Pointer object
|
|
302
|
+
* @public
|
|
303
|
+
* @constant
|
|
304
|
+
* @type String
|
|
305
|
+
* @name POINTERMOVE
|
|
306
|
+
* @memberOf me.event
|
|
307
|
+
* @see me.event.on
|
|
308
|
+
*/
|
|
309
|
+
export const POINTERMOVE = "me.event.pointermove";
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Event for dragstart events on a Draggable entity <br>
|
|
313
|
+
* Data passed:
|
|
314
|
+
* {Object} the drag event <br>
|
|
315
|
+
* {Object} the Draggable entity
|
|
316
|
+
* @public
|
|
317
|
+
* @constant
|
|
318
|
+
* @type String
|
|
319
|
+
* @name DRAGSTART
|
|
320
|
+
* @memberOf me.event
|
|
321
|
+
* @see me.event.on
|
|
322
|
+
*/
|
|
323
|
+
export const DRAGSTART = "me.game.dragstart";
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Event for dragend events on a Draggable entity <br>
|
|
327
|
+
* Data passed:
|
|
328
|
+
* {Object} the drag event <br>
|
|
329
|
+
* {Object} the Draggable entity
|
|
330
|
+
* @public
|
|
331
|
+
* @constant
|
|
332
|
+
* @type String
|
|
333
|
+
* @name DRAGEND
|
|
334
|
+
* @memberOf me.event
|
|
335
|
+
* @see me.event.on
|
|
336
|
+
*/
|
|
337
|
+
export const DRAGEND = "me.game.dragend";
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Event for when the (browser) window is resized <br>
|
|
341
|
+
* Data passed : {Event} Event object
|
|
342
|
+
* @public
|
|
343
|
+
* @constant
|
|
344
|
+
* @type String
|
|
345
|
+
* @name WINDOW_ONRESIZE
|
|
346
|
+
* @memberOf me.event
|
|
347
|
+
* @see me.event.on
|
|
348
|
+
*/
|
|
349
|
+
export const WINDOW_ONRESIZE = "window.onresize";
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Event for when the canvas is resized <br>
|
|
353
|
+
* (this usually follows a WINDOW_ONRESIZE event).<br>
|
|
354
|
+
* Data passed : {Number} canvas width <br>
|
|
355
|
+
* Data passed : {Number} canvas height
|
|
356
|
+
* @public
|
|
357
|
+
* @constant
|
|
358
|
+
* @type String
|
|
359
|
+
* @name CANVAS_ONRESIZE
|
|
360
|
+
* @memberOf me.event
|
|
361
|
+
* @see me.event.on
|
|
362
|
+
*/
|
|
363
|
+
export const CANVAS_ONRESIZE = "canvas.onresize";
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Event for when the viewport is resized <br>
|
|
367
|
+
* (this usually follows a WINDOW_ONRESIZE event, when using the `flex` scaling mode is used and after the viewport was updated).<br>
|
|
368
|
+
* Data passed : {Number} viewport width <br>
|
|
369
|
+
* Data passed : {Number} viewport height
|
|
370
|
+
* @public
|
|
371
|
+
* @constant
|
|
372
|
+
* @type String
|
|
373
|
+
* @name VIEWPORT_ONRESIZE
|
|
374
|
+
* @memberOf me.event
|
|
375
|
+
* @see me.event.on
|
|
376
|
+
*/
|
|
377
|
+
export const VIEWPORT_ONRESIZE = "viewport.onresize";
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Event for when the device is rotated <br>
|
|
381
|
+
* Data passed : {Event} Event object <br>
|
|
382
|
+
* @public
|
|
383
|
+
* @constant
|
|
384
|
+
* @type String
|
|
385
|
+
* @name WINDOW_ONORIENTATION_CHANGE
|
|
386
|
+
* @memberOf me.event
|
|
387
|
+
* @see me.event.on
|
|
388
|
+
*/
|
|
389
|
+
export const WINDOW_ONORIENTATION_CHANGE = "window.orientationchange";
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Event for when the (browser) window is scrolled <br>
|
|
393
|
+
* Data passed : {Event} Event object
|
|
394
|
+
* @public
|
|
395
|
+
* @constant
|
|
396
|
+
* @type String
|
|
397
|
+
* @name WINDOW_ONSCROLL
|
|
398
|
+
* @memberOf me.event
|
|
399
|
+
* @see me.event.on
|
|
400
|
+
*/
|
|
401
|
+
export const WINDOW_ONSCROLL = "window.onscroll";
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Event for when the viewport position is updated <br>
|
|
405
|
+
* Data passed : {me.Vector2d} viewport position vector
|
|
406
|
+
* @public
|
|
407
|
+
* @constant
|
|
408
|
+
* @type String
|
|
409
|
+
* @name VIEWPORT_ONCHANGE
|
|
410
|
+
* @memberOf me.event
|
|
411
|
+
* @see me.event.on
|
|
412
|
+
*/
|
|
413
|
+
export const VIEWPORT_ONCHANGE = "viewport.onchange";
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Event for when WebGL context is lost <br>
|
|
417
|
+
* Data passed : {me.WebGLRenderer} the current webgl renderer instance`
|
|
418
|
+
* @public
|
|
419
|
+
* @constant
|
|
420
|
+
* @type String
|
|
421
|
+
* @name WEBGL_ONCONTEXT_LOST
|
|
422
|
+
* @memberOf me.event
|
|
423
|
+
* @see me.event.on
|
|
424
|
+
*/
|
|
425
|
+
export const WEBGL_ONCONTEXT_LOST = "renderer.webglcontextlost";
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Event for when WebGL context is restored <br>
|
|
429
|
+
* Data passed : {me.WebGLRenderer} the current webgl renderer instance`
|
|
430
|
+
* @public
|
|
431
|
+
* @constant
|
|
432
|
+
* @type String
|
|
433
|
+
* @name WEBGL_ONCONTEXT_RESTORED
|
|
434
|
+
* @memberOf me.event
|
|
435
|
+
* @see me.event.on
|
|
436
|
+
*/
|
|
437
|
+
export const WEBGL_ONCONTEXT_RESTORED = "renderer.webglcontextrestored";
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* calls each of the listeners registered for a given event.
|
|
441
|
+
* @function me.event.emit
|
|
442
|
+
* @param {(String|Symbol)} event The event name.
|
|
443
|
+
* @param {...*} arguments arguments to be passed to all listeners
|
|
444
|
+
* @return true if the event had listeners, false otherwise.
|
|
445
|
+
* @example
|
|
446
|
+
* me.event.emit("event-name", a, b, c);
|
|
447
|
+
*/
|
|
448
|
+
export function emit(eventName, ...args) {
|
|
449
|
+
return eventEmitter.emit(eventName, ...args);
|
|
439
450
|
};
|
|
440
451
|
|
|
441
|
-
|
|
452
|
+
/**
|
|
453
|
+
* Add a listener for a given event.
|
|
454
|
+
* @function me.event.on
|
|
455
|
+
* @param {(String|Symbol)} event The event name.
|
|
456
|
+
* @param {Function} fn The listener function.
|
|
457
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
458
|
+
* @returns {EventEmitter} `this`.
|
|
459
|
+
* @public
|
|
460
|
+
* @example
|
|
461
|
+
* me.event.on("event-name", myFunction, this);
|
|
462
|
+
*/
|
|
463
|
+
export function on(eventName, listener, context) {
|
|
464
|
+
return eventEmitter.on(eventName, listener, context);
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Add a one-time listener for a given event.
|
|
469
|
+
* @function me.event.once
|
|
470
|
+
* @param {(String|Symbol)} event The event name.
|
|
471
|
+
* @param {Function} fn The listener function.
|
|
472
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
473
|
+
* @returns {EventEmitter} `this`.
|
|
474
|
+
* @public
|
|
475
|
+
* @example
|
|
476
|
+
* me.event.once("event-name", myFunction, this);
|
|
477
|
+
*/
|
|
478
|
+
export function once(eventName, listener, context) {
|
|
479
|
+
return eventEmitter.once(eventName, listener, context);
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* remove the given listener for a given event.
|
|
484
|
+
* @function me.event.off
|
|
485
|
+
* @param {(String|Symbol)} event The event name.
|
|
486
|
+
* @param {Function} fn The listener function.
|
|
487
|
+
* @returns {EventEmitter} `this`.
|
|
488
|
+
* @public
|
|
489
|
+
* @example
|
|
490
|
+
* me.event.off("event-name", myFunction);
|
|
491
|
+
*/
|
|
492
|
+
export function off(eventName, listener) {
|
|
493
|
+
return eventEmitter.off(eventName, listener);
|
|
494
|
+
};
|