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.
Files changed (78) hide show
  1. package/{LICENSE → LICENSE.md} +0 -0
  2. package/README.md +93 -57
  3. package/dist/melonjs.js +10334 -11179
  4. package/dist/melonjs.min.js +4 -10
  5. package/dist/melonjs.module.d.ts +13206 -0
  6. package/dist/melonjs.module.js +9913 -10872
  7. package/package.json +19 -14
  8. package/src/audio/audio.js +477 -553
  9. package/src/camera/camera2d.js +67 -65
  10. package/src/entity/draggable.js +26 -35
  11. package/src/entity/droptarget.js +17 -14
  12. package/src/entity/entity.js +59 -79
  13. package/src/game.js +194 -204
  14. package/src/index.js +12 -30
  15. package/src/input/gamepad.js +8 -19
  16. package/src/input/keyboard.js +4 -4
  17. package/src/input/pointer.js +14 -12
  18. package/src/input/pointerevent.js +15 -13
  19. package/src/lang/deprecated.js +2 -887
  20. package/src/level/level.js +3 -3
  21. package/src/level/tiled/TMXGroup.js +7 -11
  22. package/src/level/tiled/TMXLayer.js +33 -32
  23. package/src/level/tiled/TMXTileMap.js +15 -19
  24. package/src/level/tiled/TMXTileset.js +5 -5
  25. package/src/level/tiled/TMXUtils.js +3 -3
  26. package/src/level/tiled/renderer/TMXRenderer.js +4 -0
  27. package/src/loader/loader.js +8 -23
  28. package/src/loader/loadingscreen.js +51 -60
  29. package/src/math/matrix3.js +1 -1
  30. package/src/particles/emitter.js +36 -39
  31. package/src/particles/particle.js +27 -12
  32. package/src/particles/particlecontainer.js +17 -16
  33. package/src/physics/body.js +80 -118
  34. package/src/physics/collision.js +5 -235
  35. package/src/physics/detector.js +235 -0
  36. package/src/physics/quadtree.js +14 -14
  37. package/src/physics/world.js +84 -18
  38. package/src/plugin/plugin.js +26 -24
  39. package/src/polyfill/console.js +9 -14
  40. package/src/renderable/GUI.js +48 -62
  41. package/src/renderable/collectable.js +11 -4
  42. package/src/renderable/colorlayer.js +28 -26
  43. package/src/renderable/container.js +120 -96
  44. package/src/renderable/imagelayer.js +94 -93
  45. package/src/renderable/renderable.js +164 -138
  46. package/src/renderable/sprite.js +42 -44
  47. package/src/renderable/trigger.js +24 -17
  48. package/src/shapes/ellipse.js +27 -27
  49. package/src/shapes/line.js +12 -8
  50. package/src/shapes/poly.js +77 -49
  51. package/src/shapes/rectangle.js +193 -268
  52. package/src/state/stage.js +23 -25
  53. package/src/state/state.js +35 -86
  54. package/src/system/device.js +233 -285
  55. package/src/system/event.js +485 -432
  56. package/src/system/pooling.js +61 -54
  57. package/src/system/save.js +17 -16
  58. package/src/system/timer.js +34 -38
  59. package/src/text/bitmaptext.js +44 -46
  60. package/src/text/text.js +39 -34
  61. package/src/tweens/easing.js +0 -2
  62. package/src/tweens/interpolation.js +3 -8
  63. package/src/tweens/tween.js +332 -351
  64. package/src/utils/function.js +6 -8
  65. package/src/utils/utils.js +34 -30
  66. package/src/video/canvas/canvas_renderer.js +13 -8
  67. package/src/video/renderer.js +8 -7
  68. package/src/video/texture.js +8 -8
  69. package/src/video/texture_cache.js +5 -5
  70. package/src/video/video.js +373 -403
  71. package/src/video/webgl/glshader.js +2 -2
  72. package/src/video/webgl/webgl_compositor.js +14 -8
  73. package/src/video/webgl/webgl_renderer.js +21 -19
  74. package/plugins/debug/debugPanel.js +0 -770
  75. package/plugins/debug/font/PressStart2P.fnt +0 -100
  76. package/plugins/debug/font/PressStart2P.ltr +0 -1
  77. package/plugins/debug/font/PressStart2P.png +0 -0
  78. package/plugins/debug/particleDebugPanel.js +0 -303
@@ -1,303 +0,0 @@
1
- /*
2
- * MelonJS Game Engine
3
- * Copyright (C) 2011 - 2019 Olivier Biot
4
- * http://www.melonjs.org
5
- *
6
- * a simple particle debug panel plugin
7
- * usage : me.plugin.register.defer(this, me.debug.ParticlePanel, "particledebug");
8
- *
9
- * note :
10
- * Heap Memory information is available under Chrome when using
11
- * the "--enable-memory-info" parameter to launch Chrome
12
- */
13
-
14
- (function () {
15
-
16
- // ensure that me.debug is defined
17
- me.debug = me.debug || {};
18
-
19
- var ParticlePanel = me.Renderable.extend({
20
-
21
- /** @private */
22
- init : function () {
23
- // call the super constructor
24
- this._super(me.Renderable, "init", [ 0, me.video.renderer.getHeight() - 60, 200, 60 ]);
25
-
26
- // minimum melonJS version expected
27
- this.version = "8.0.0";
28
-
29
- // to hold the debug options
30
- // clickable rect area
31
- this.area = {};
32
-
33
- // for z ordering
34
- // make it ridiculously high
35
- this.pos.z = Infinity;
36
-
37
- // visibility flag
38
- this.visible = true;
39
-
40
- // set the object GUID value
41
- this.GUID = "particledebug-" + me.utils.createGUID();
42
-
43
- // set the object entity name
44
- this.name = "me.particleDebugPanel";
45
-
46
- // persistent
47
- this.isPersistent = true;
48
-
49
- // a floating object
50
- this.floating = true;
51
-
52
- // always update, even when not visible
53
- this.alwaysUpdate = true;
54
-
55
- // create a default font, with fixed char width
56
- this.font = new me.Text(0, 0, {
57
- font: "courier",
58
- fillStyle : "#FFFFFF",
59
- size: 10
60
- });
61
-
62
- // sample points
63
- this.frameUpdateTimeSamples = [];
64
- this.frameDrawTimeSamples = [];
65
- this.updateTimeSamples = [];
66
- this.drawTimeSamples = [];
67
- this.updateTime = 0;
68
- this.drawTime = 0;
69
- this.updateTimeAvg = 0;
70
- this.drawTimeAvg = 0;
71
- this.frameUpdateTimeAvg = 0;
72
- this.frameDrawTimeAvg = 0;
73
-
74
- this.emitterCount = 0;
75
- this.particleCount = 0;
76
-
77
- //patch patch patch !
78
- this.patchSystemFn();
79
-
80
- // add the debug panel to the game world
81
- me.game.world.addChild(this, Infinity);
82
- },
83
-
84
-
85
- /**
86
- * patch system fn to draw debug information
87
- */
88
- patchSystemFn : function () {
89
- var _this = this;
90
- var now = Date.now;
91
- if (window.performance && window.performance.now) {
92
- now = window.performance.now.bind(window.performance);
93
- }
94
-
95
- // patch me.ParticleEmitter.init
96
- me.plugin.patch(me.ParticleEmitter, "init", function (x, y, image) {
97
- this._patched.apply(this, arguments);
98
- _this.emitterCount++;
99
- });
100
-
101
- // patch me.ParticleEmitter.destroy
102
- me.plugin.patch(me.ParticleEmitter, "destroy", function () {
103
- this._patched.apply(this, arguments);
104
- _this.emitterCount--;
105
- });
106
-
107
- // patch me.Particle.init
108
- me.plugin.patch(me.Particle, "init", function (emitter) {
109
- this._patched.apply(this, arguments);
110
- _this.particleCount++;
111
- });
112
-
113
- // patch me.Particle.destroy
114
- me.Particle.prototype.destroy = function () {
115
- _this.particleCount--;
116
- };
117
-
118
- // patch me.game.update
119
- me.plugin.patch(me.game, "update", function (dt) {
120
- var startTime = now();
121
- this._patched.apply(this, arguments);
122
- // calculate the update time (can't we use [dt] here ?)
123
- _this.frameUpdateTimeSamples.push(now() - startTime);
124
- });
125
-
126
- // patch me.game.draw
127
- me.plugin.patch(me.game, "draw", function () {
128
- var startTime = now();
129
- this._patched.apply(this, arguments);
130
- // calculate the drawing time
131
- _this.frameDrawTimeSamples.push(now() - startTime);
132
- });
133
-
134
- // patch me.ParticleContainer.update
135
- me.plugin.patch(me.ParticleContainer, "update", function (dt) {
136
- var startTime = now();
137
- var value = this._patched.apply(this, arguments);
138
- // calculate the update time (can't we use [dt] here ?)
139
- _this.updateTime += now() - startTime;
140
- return value;
141
- });
142
-
143
- // patch me.ParticleContainer.draw
144
- me.plugin.patch(me.ParticleContainer, "draw", function (renderer, rect) {
145
- var startTime = now();
146
- this._patched.apply(this, arguments);
147
- // calculate the drawing time
148
- _this.drawTime += now() - startTime;
149
- });
150
- },
151
-
152
- /** @private */
153
- update : function () {
154
- return true;
155
- },
156
-
157
-
158
- /**
159
- * @private
160
- */
161
- drawGraph : function (renderer) {
162
- var updateTimeSamples = this.updateTimeSamples;
163
- var drawTimeSamples = this.drawTimeSamples;
164
- var frameUpdateTimeSamples = this.frameUpdateTimeSamples;
165
- var frameDrawTimeSamples = this.frameDrawTimeSamples;
166
- var width = this._bounds.width, height = this._bounds.height;
167
-
168
- while (updateTimeSamples.length > width) {
169
- updateTimeSamples.shift();
170
- }
171
- while (drawTimeSamples.length > width) {
172
- drawTimeSamples.shift();
173
- }
174
- while (frameUpdateTimeSamples.length > width) {
175
- frameUpdateTimeSamples.shift();
176
- }
177
- while (frameDrawTimeSamples.length > width) {
178
- frameDrawTimeSamples.shift();
179
- }
180
-
181
- var maxTime = 60, scale = height / maxTime, len = updateTimeSamples.length;
182
- var frameTimeLimit = 1000 / me.timer.maxfps, where = height - frameTimeLimit * scale;
183
-
184
- renderer.setColor("#80808080");
185
- renderer.strokeLine(0, where, width, where);
186
- renderer.setColor("#FFFFFFFF");
187
-
188
-
189
- var updateTimeSum = 0, drawTimeSum = 0, frameUpdateTimeSum = 0, frameDrawTimeSum = 0, update = [], slowUpdate = [], draw = [], slowDraw = [];
190
- // prepare data
191
- for (var x = 0, updateTime, drawTime, slow; x < len; ++x) {
192
- updateTime = updateTimeSamples[x] || 0;
193
- drawTime = drawTimeSamples[x] || 0;
194
- slow = (updateTime + drawTime > frameTimeLimit);
195
- updateTimeSum += updateTime;
196
- drawTimeSum += drawTime;
197
- frameUpdateTimeSum += frameUpdateTimeSamples[x] || 0;
198
- frameDrawTimeSum += frameDrawTimeSamples[x] || 0;
199
-
200
- updateTime *= scale;
201
- update.push(slow ? 0 : updateTime);
202
- slowUpdate.push(slow ? updateTime : 0);
203
-
204
- drawTime = updateTime + drawTime * scale;
205
- draw.push(slow ? 0 : drawTime);
206
- slowDraw.push(slow ? drawTime : 0);
207
- }
208
- this.updateTimeAvg = updateTimeSum / len;
209
- this.drawTimeAvg = drawTimeSum / len;
210
- this.frameUpdateTimeAvg = frameUpdateTimeSum / len;
211
- this.frameDrawTimeAvg = frameDrawTimeSum / len;
212
-
213
- // draw the graph
214
- this.fillArea(renderer, width, height, draw, "lightblue");
215
- this.fillArea(renderer, width, height, slowDraw, "lightcoral");
216
- this.fillArea(renderer, width, height, update, "lightgreen");
217
- this.fillArea(renderer, width, height, slowUpdate, "lightsalmon");
218
-
219
- renderer.setGlobalAlpha(1.0);
220
- },
221
-
222
- /**
223
- * @private
224
- */
225
- fillArea : function (renderer, width, height, data, color) {
226
- var i, x, y, len = data.length;
227
- var context = renderer.getContext();
228
- context.fillStyle = color;
229
- context.beginPath();
230
- context.moveTo(width, height);
231
- for (i = len; i--;) {
232
- x = width - (len - i);
233
- y = height - data[i];
234
- context.lineTo(x, y < 0 ? 0 : y);
235
- context.lineTo(x - 1, y < 0 ? 0 : y);
236
- }
237
- context.lineTo(0, height);
238
- context.closePath();
239
- context.fill();
240
- },
241
-
242
- /** @private */
243
- draw : function (renderer) {
244
- renderer.save();
245
-
246
- // draw the panel
247
- renderer.setColor("#00000080");
248
-
249
- renderer.fillRect(this._bounds.left, this._bounds.top,
250
- this._bounds.width, this._bounds.height);
251
- renderer.translate(this._bounds.left, this._bounds.top);
252
-
253
- renderer.setColor("#FFFFFFFF");
254
-
255
- // # entities / draw
256
- this.font.draw(renderer, "emitters : " + this.emitterCount, 5, 5);
257
- this.font.draw(renderer, "particles : " + this.particleCount, 5, 18);
258
-
259
- // draw the update duration
260
- this.font.draw(renderer, "update: " + this.updateTimeAvg.toFixed(2) + "ms / " + this.frameUpdateTimeAvg.toFixed(2) + "ms", 5, 31);
261
-
262
- // draw the draw duration
263
- this.font.draw(renderer, "draw: " + this.drawTimeAvg.toFixed(2) + "ms / " + this.frameDrawTimeAvg.toFixed(2) + "ms", 5, 44);
264
-
265
- this.updateTimeSamples.push(this.updateTime);
266
- this.updateTime = 0;
267
- this.drawTimeSamples.push(this.drawTime);
268
- this.drawTime = 0;
269
-
270
- // draw the graph
271
- this.drawGraph(renderer);
272
-
273
- renderer.restore();
274
- }
275
- });
276
-
277
- /**
278
- * @class
279
- * @public
280
- * @extends me.plugin.Base
281
- * @memberOf me
282
- * @constructor
283
- */
284
- me.debug.ParticlePanel = me.plugin.Base.extend({
285
-
286
- /** @private */
287
- init : function () {
288
- // call the super constructor
289
- this._super(me.plugin.Base, "init");
290
-
291
- this.panel = new ParticlePanel();
292
- }
293
- });
294
-
295
- // automatically register the debug panel
296
- me.device.onReady(function () {
297
- me.utils.function.defer(me.plugin.register, this, me.debug.ParticlePanel, "particleDebugPanel");
298
- });
299
-
300
- /*---------------------------------------------------------*/
301
- // END END END
302
- /*---------------------------------------------------------*/
303
- })();