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/renderable/GUI.js
CHANGED
|
@@ -18,24 +18,21 @@ import { registerPointerEvent, releasePointerEvent} from "./../input/input.js";
|
|
|
18
18
|
* @example
|
|
19
19
|
*
|
|
20
20
|
* // create a basic GUI Object
|
|
21
|
-
*
|
|
22
|
-
* {
|
|
23
|
-
* init:function (x, y)
|
|
24
|
-
* {
|
|
21
|
+
* class myButton extends GUI_Object {
|
|
22
|
+
* constructor(x, y) {
|
|
25
23
|
* var settings = {}
|
|
26
24
|
* settings.image = "button";
|
|
27
25
|
* settings.framewidth = 100;
|
|
28
26
|
* settings.frameheight = 50;
|
|
29
27
|
* // super constructor
|
|
30
|
-
*
|
|
28
|
+
* super(x, y, settings);
|
|
31
29
|
* // define the object z order
|
|
32
30
|
* this.pos.z = 4;
|
|
33
|
-
* }
|
|
31
|
+
* }
|
|
34
32
|
*
|
|
35
33
|
* // output something in the console
|
|
36
34
|
* // when the object is clicked
|
|
37
|
-
* onClick:function (event)
|
|
38
|
-
* {
|
|
35
|
+
* onClick:function (event) {
|
|
39
36
|
* console.log("clicked!");
|
|
40
37
|
* // don't propagate the event
|
|
41
38
|
* return false;
|
|
@@ -46,11 +43,17 @@ import { registerPointerEvent, releasePointerEvent} from "./../input/input.js";
|
|
|
46
43
|
* me.game.world.addChild(new myButton(10,10));
|
|
47
44
|
*
|
|
48
45
|
*/
|
|
49
|
-
|
|
46
|
+
|
|
47
|
+
class GUI_Object extends Sprite {
|
|
48
|
+
|
|
50
49
|
/**
|
|
51
50
|
* @ignore
|
|
52
51
|
*/
|
|
53
|
-
|
|
52
|
+
constructor(x, y, settings) {
|
|
53
|
+
|
|
54
|
+
// call the parent constructor
|
|
55
|
+
super(x, y, settings);
|
|
56
|
+
|
|
54
57
|
/**
|
|
55
58
|
* object can be clicked or not
|
|
56
59
|
* @public
|
|
@@ -88,46 +91,23 @@ var GUI_Object = Sprite.extend({
|
|
|
88
91
|
|
|
89
92
|
// object has been updated (clicked,etc..)
|
|
90
93
|
this.holdTimeout = null;
|
|
91
|
-
this.updated = false;
|
|
92
94
|
this.released = true;
|
|
93
95
|
|
|
94
|
-
// call the parent constructor
|
|
95
|
-
this._super(Sprite, "init", [ x, y, settings ]);
|
|
96
|
-
|
|
97
96
|
// GUI items use screen coordinates
|
|
98
97
|
this.floating = true;
|
|
99
98
|
|
|
100
99
|
// enable event detection
|
|
101
100
|
this.isKinematic = false;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* return true if the object has been clicked
|
|
106
|
-
* @ignore
|
|
107
|
-
*/
|
|
108
|
-
update : function (dt) {
|
|
109
|
-
// call the parent constructor
|
|
110
|
-
var updated = this._super(Sprite, "update", [ dt ]);
|
|
111
|
-
// check if the button was updated
|
|
112
|
-
if (this.updated) {
|
|
113
|
-
// clear the flag
|
|
114
|
-
if (!this.released) {
|
|
115
|
-
this.updated = false;
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
// else only return true/false based on the parent function
|
|
120
|
-
return updated;
|
|
121
|
-
},
|
|
101
|
+
}
|
|
122
102
|
|
|
123
103
|
/**
|
|
124
104
|
* function callback for the pointerdown event
|
|
125
105
|
* @ignore
|
|
126
106
|
*/
|
|
127
|
-
clicked
|
|
107
|
+
clicked(event) {
|
|
128
108
|
// Check if left mouse button is pressed
|
|
129
109
|
if (event.button === 0 && this.isClickable) {
|
|
130
|
-
this.
|
|
110
|
+
this.dirty = true;
|
|
131
111
|
this.released = false;
|
|
132
112
|
if (this.isHoldable) {
|
|
133
113
|
if (this.holdTimeout !== null) {
|
|
@@ -136,9 +116,9 @@ var GUI_Object = Sprite.extend({
|
|
|
136
116
|
this.holdTimeout = timer.setTimeout(this.hold.bind(this), this.holdThreshold, false);
|
|
137
117
|
this.released = false;
|
|
138
118
|
}
|
|
139
|
-
return this.onClick
|
|
119
|
+
return this.onClick(event);
|
|
140
120
|
}
|
|
141
|
-
}
|
|
121
|
+
}
|
|
142
122
|
|
|
143
123
|
/**
|
|
144
124
|
* function called when the object is pressed <br>
|
|
@@ -150,18 +130,19 @@ var GUI_Object = Sprite.extend({
|
|
|
150
130
|
* @function
|
|
151
131
|
* @param {Event} event the event object
|
|
152
132
|
*/
|
|
153
|
-
onClick
|
|
133
|
+
onClick(/* event */) {
|
|
154
134
|
return false;
|
|
155
|
-
}
|
|
135
|
+
}
|
|
156
136
|
|
|
157
137
|
/**
|
|
158
138
|
* function callback for the pointerEnter event
|
|
159
139
|
* @ignore
|
|
160
140
|
*/
|
|
161
|
-
enter
|
|
141
|
+
enter(event) {
|
|
162
142
|
this.hover = true;
|
|
163
|
-
|
|
164
|
-
|
|
143
|
+
this.dirty = true;
|
|
144
|
+
return this.onOver(event);
|
|
145
|
+
}
|
|
165
146
|
|
|
166
147
|
/**
|
|
167
148
|
* function called when the pointer is over the object
|
|
@@ -171,17 +152,18 @@ var GUI_Object = Sprite.extend({
|
|
|
171
152
|
* @function
|
|
172
153
|
* @param {Event} event the event object
|
|
173
154
|
*/
|
|
174
|
-
onOver
|
|
155
|
+
onOver(/* event */) {}
|
|
175
156
|
|
|
176
157
|
/**
|
|
177
158
|
* function callback for the pointerLeave event
|
|
178
159
|
* @ignore
|
|
179
160
|
*/
|
|
180
|
-
leave
|
|
161
|
+
leave(event) {
|
|
181
162
|
this.hover = false;
|
|
182
|
-
this.
|
|
183
|
-
|
|
184
|
-
|
|
163
|
+
this.dirty = true;
|
|
164
|
+
this.release(event);
|
|
165
|
+
return this.onOut(event);
|
|
166
|
+
}
|
|
185
167
|
|
|
186
168
|
/**
|
|
187
169
|
* function called when the pointer is leaving the object area
|
|
@@ -191,19 +173,22 @@ var GUI_Object = Sprite.extend({
|
|
|
191
173
|
* @function
|
|
192
174
|
* @param {Event} event the event object
|
|
193
175
|
*/
|
|
194
|
-
onOut
|
|
176
|
+
onOut(/* event */) {
|
|
177
|
+
|
|
178
|
+
}
|
|
195
179
|
|
|
196
180
|
/**
|
|
197
181
|
* function callback for the pointerup event
|
|
198
182
|
* @ignore
|
|
199
183
|
*/
|
|
200
|
-
release
|
|
184
|
+
release(event) {
|
|
201
185
|
if (this.released === false) {
|
|
202
186
|
this.released = true;
|
|
187
|
+
this.dirty = true;
|
|
203
188
|
timer.clearTimeout(this.holdTimeout);
|
|
204
|
-
return this.onRelease
|
|
189
|
+
return this.onRelease(event);
|
|
205
190
|
}
|
|
206
|
-
}
|
|
191
|
+
}
|
|
207
192
|
|
|
208
193
|
/**
|
|
209
194
|
* function called when the object is pressed and released <br>
|
|
@@ -215,20 +200,21 @@ var GUI_Object = Sprite.extend({
|
|
|
215
200
|
* @function
|
|
216
201
|
* @param {Event} event the event object
|
|
217
202
|
*/
|
|
218
|
-
onRelease
|
|
203
|
+
onRelease() {
|
|
219
204
|
return false;
|
|
220
|
-
}
|
|
205
|
+
}
|
|
221
206
|
|
|
222
207
|
/**
|
|
223
208
|
* function callback for the tap and hold timer event
|
|
224
209
|
* @ignore
|
|
225
210
|
*/
|
|
226
|
-
hold
|
|
211
|
+
hold() {
|
|
227
212
|
timer.clearTimeout(this.holdTimeout);
|
|
213
|
+
this.dirty = true;
|
|
228
214
|
if (!this.released) {
|
|
229
|
-
this.onHold
|
|
215
|
+
this.onHold();
|
|
230
216
|
}
|
|
231
|
-
}
|
|
217
|
+
}
|
|
232
218
|
|
|
233
219
|
/**
|
|
234
220
|
* function called when the object is pressed and held<br>
|
|
@@ -238,26 +224,26 @@ var GUI_Object = Sprite.extend({
|
|
|
238
224
|
* @public
|
|
239
225
|
* @function
|
|
240
226
|
*/
|
|
241
|
-
onHold
|
|
227
|
+
onHold() {}
|
|
242
228
|
|
|
243
229
|
/**
|
|
244
230
|
* function called when added to the game world or a container
|
|
245
231
|
* @ignore
|
|
246
232
|
*/
|
|
247
|
-
onActivateEvent
|
|
233
|
+
onActivateEvent() {
|
|
248
234
|
// register pointer events
|
|
249
235
|
registerPointerEvent("pointerdown", this, this.clicked.bind(this));
|
|
250
236
|
registerPointerEvent("pointerup", this, this.release.bind(this));
|
|
251
237
|
registerPointerEvent("pointercancel", this, this.release.bind(this));
|
|
252
238
|
registerPointerEvent("pointerenter", this, this.enter.bind(this));
|
|
253
239
|
registerPointerEvent("pointerleave", this, this.leave.bind(this));
|
|
254
|
-
}
|
|
240
|
+
}
|
|
255
241
|
|
|
256
242
|
/**
|
|
257
243
|
* function called when removed from the game world or a container
|
|
258
244
|
* @ignore
|
|
259
245
|
*/
|
|
260
|
-
onDeactivateEvent
|
|
246
|
+
onDeactivateEvent() {
|
|
261
247
|
// release pointer events
|
|
262
248
|
releasePointerEvent("pointerdown", this);
|
|
263
249
|
releasePointerEvent("pointerup", this);
|
|
@@ -266,6 +252,6 @@ var GUI_Object = Sprite.extend({
|
|
|
266
252
|
releasePointerEvent("pointerleave", this);
|
|
267
253
|
timer.clearTimeout(this.holdTimeout);
|
|
268
254
|
}
|
|
269
|
-
}
|
|
255
|
+
};
|
|
270
256
|
|
|
271
257
|
export default GUI_Object;
|
|
@@ -4,6 +4,7 @@ import Rect from "./../shapes/rectangle.js";
|
|
|
4
4
|
import collision from "./../physics/collision.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
+
* @classdesc
|
|
7
8
|
* a basic collectable helper class for immovable object (e.g. a coin)
|
|
8
9
|
* @class
|
|
9
10
|
* @extends me.Sprite
|
|
@@ -13,13 +14,15 @@ import collision from "./../physics/collision.js";
|
|
|
13
14
|
* @param {Number} y the y coordinates of the collectable
|
|
14
15
|
* @param {Object} settings See {@link me.Sprite}
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
class Collectable extends Sprite {
|
|
17
19
|
/**
|
|
18
20
|
* @ignore
|
|
19
21
|
*/
|
|
20
|
-
|
|
22
|
+
constructor(x, y, settings) {
|
|
23
|
+
|
|
21
24
|
// call the super constructor
|
|
22
|
-
|
|
25
|
+
super(x, y, settings);
|
|
23
26
|
|
|
24
27
|
this.name = settings.name;
|
|
25
28
|
this.type = settings.type;
|
|
@@ -28,6 +31,9 @@ var Collectable = Sprite.extend({
|
|
|
28
31
|
// add and configure the physic body
|
|
29
32
|
this.body = new Body(this, settings.shapes || new Rect(0, 0, this.width, this.height));
|
|
30
33
|
this.body.collisionType = collision.types.COLLECTABLE_OBJECT;
|
|
34
|
+
// by default only collides with PLAYER_OBJECT
|
|
35
|
+
this.body.setCollisionMask(collision.types.PLAYER_OBJECT);
|
|
36
|
+
this.body.setStatic(true);
|
|
31
37
|
|
|
32
38
|
// Update anchorPoint
|
|
33
39
|
if (settings.anchorPoint) {
|
|
@@ -38,6 +44,7 @@ var Collectable = Sprite.extend({
|
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
}
|
|
41
|
-
|
|
47
|
+
|
|
48
|
+
};
|
|
42
49
|
|
|
43
50
|
export default Collectable;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import Color from "./../math/color.js";
|
|
2
1
|
import pool from "./../system/pooling.js";
|
|
3
|
-
import
|
|
2
|
+
import { viewport } from "./../game.js";
|
|
4
3
|
import Renderable from "./renderable.js";
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
/**
|
|
7
|
+
* @classdesc
|
|
8
8
|
* a generic Color Layer Object. Fills the entire Canvas with the color not just the container the object belongs to.
|
|
9
9
|
* @class
|
|
10
10
|
* @extends me.Renderable
|
|
@@ -12,20 +12,16 @@ import Renderable from "./renderable.js";
|
|
|
12
12
|
* @constructor
|
|
13
13
|
* @param {String} name Layer name
|
|
14
14
|
* @param {me.Color|String} color CSS color
|
|
15
|
-
* @param {Number} z z-index position
|
|
15
|
+
* @param {Number} [z = 0] z-index position
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
class ColorLayer extends Renderable {
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* @ignore
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
constructor(name, color, z) {
|
|
22
23
|
// parent constructor
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// apply given parameters
|
|
26
|
-
this.name = name;
|
|
27
|
-
this.pos.z = z;
|
|
28
|
-
this.floating = true;
|
|
24
|
+
super(0, 0, Infinity, Infinity);
|
|
29
25
|
|
|
30
26
|
/**
|
|
31
27
|
* the layer color component
|
|
@@ -34,40 +30,46 @@ var ColorLayer = Renderable.extend({
|
|
|
34
30
|
* @name color
|
|
35
31
|
* @memberOf me.ColorLayer#
|
|
36
32
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
this.color = pool.pull("Color").parseCSS(color);
|
|
34
|
+
|
|
35
|
+
this.onResetEvent(name, color, z);
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
onResetEvent(name, color, z = 0) {
|
|
40
|
+
// apply given parameters
|
|
41
|
+
this.name = name;
|
|
42
|
+
this.pos.z = z;
|
|
43
|
+
this.floating = true;
|
|
44
|
+
// string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
|
|
45
|
+
this.color.parseCSS(color);
|
|
46
|
+
}
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
49
|
* draw the color layer
|
|
49
50
|
* @ignore
|
|
50
51
|
*/
|
|
51
|
-
draw
|
|
52
|
+
draw(renderer, rect) {
|
|
52
53
|
var color = renderer.getColor();
|
|
53
|
-
var vpos =
|
|
54
|
+
var vpos = viewport.pos;
|
|
54
55
|
renderer.setColor(this.color);
|
|
55
56
|
renderer.fillRect(
|
|
56
57
|
rect.left - vpos.x, rect.top - vpos.y,
|
|
57
58
|
rect.width, rect.height
|
|
58
59
|
);
|
|
59
60
|
renderer.setColor(color);
|
|
60
|
-
}
|
|
61
|
+
}
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
64
|
* Destroy function
|
|
64
65
|
* @ignore
|
|
65
66
|
*/
|
|
66
|
-
destroy
|
|
67
|
+
destroy() {
|
|
67
68
|
pool.push(this.color);
|
|
68
69
|
this.color = undefined;
|
|
69
|
-
|
|
70
|
+
super.destroy();
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
+
|
|
73
|
+
};
|
|
72
74
|
|
|
73
75
|
export default ColorLayer;
|