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
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import event from "./../system/event.js";
|
|
1
|
+
import { renderer } from "./../video/video.js";
|
|
2
|
+
import * as event from "./../system/event.js";
|
|
3
3
|
import pool from "./../system/pooling.js";
|
|
4
|
-
import
|
|
4
|
+
import { viewport } from "./../game.js";
|
|
5
5
|
import Sprite from "./sprite.js";
|
|
6
|
-
import
|
|
6
|
+
import * as stringUtil from "./../utils/string.js";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
+
* @classdesc
|
|
10
11
|
* a generic Image Layer Object
|
|
11
12
|
* @class
|
|
12
13
|
* @extends me.Renderable
|
|
@@ -29,13 +30,15 @@ import utils from "./../utils/utils.js";
|
|
|
29
30
|
* repeat :"repeat-x"
|
|
30
31
|
* }), 1);
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
class ImageLayer extends Sprite {
|
|
35
|
+
|
|
33
36
|
/**
|
|
34
37
|
* @ignore
|
|
35
38
|
*/
|
|
36
|
-
|
|
39
|
+
constructor(x, y, settings) {
|
|
37
40
|
// call the constructor
|
|
38
|
-
|
|
41
|
+
super(x, y, settings);
|
|
39
42
|
|
|
40
43
|
// render in screen coordinates
|
|
41
44
|
this.floating = true;
|
|
@@ -59,7 +62,7 @@ var ImageLayer = Sprite.extend({
|
|
|
59
62
|
|
|
60
63
|
if (typeof(settings.ratio) !== "undefined") {
|
|
61
64
|
// little hack for backward compatiblity
|
|
62
|
-
if (
|
|
65
|
+
if (stringUtil.isNumeric(settings.ratio)) {
|
|
63
66
|
this.ratio.set(settings.ratio, +settings.ratio);
|
|
64
67
|
} else /* vector */ {
|
|
65
68
|
this.ratio.setV(settings.ratio);
|
|
@@ -94,78 +97,77 @@ var ImageLayer = Sprite.extend({
|
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
/**
|
|
98
|
-
* Define if and how an Image Layer should be repeated.<br>
|
|
99
|
-
* By default, an Image Layer is repeated both vertically and horizontally.<br>
|
|
100
|
-
* Acceptable values : <br>
|
|
101
|
-
* * 'repeat' - The background image will be repeated both vertically and horizontally <br>
|
|
102
|
-
* * 'repeat-x' - The background image will be repeated only horizontally.<br>
|
|
103
|
-
* * 'repeat-y' - The background image will be repeated only vertically.<br>
|
|
104
|
-
* * 'no-repeat' - The background-image will not be repeated.<br>
|
|
105
|
-
* @public
|
|
106
|
-
* @type String
|
|
107
|
-
* @default 'repeat'
|
|
108
|
-
* @name me.ImageLayer#repeat
|
|
109
|
-
*/
|
|
110
|
-
Object.defineProperty(this, "repeat", {
|
|
111
|
-
/**
|
|
112
|
-
* @ignore
|
|
113
|
-
*/
|
|
114
|
-
get : function get() {
|
|
115
|
-
return this._repeat;
|
|
116
|
-
},
|
|
117
|
-
/**
|
|
118
|
-
* @ignore
|
|
119
|
-
*/
|
|
120
|
-
set : function set(val) {
|
|
121
|
-
this._repeat = val;
|
|
122
|
-
switch (this._repeat) {
|
|
123
|
-
case "no-repeat" :
|
|
124
|
-
this.repeatX = false;
|
|
125
|
-
this.repeatY = false;
|
|
126
|
-
break;
|
|
127
|
-
case "repeat-x" :
|
|
128
|
-
this.repeatX = true;
|
|
129
|
-
this.repeatY = false;
|
|
130
|
-
break;
|
|
131
|
-
case "repeat-y" :
|
|
132
|
-
this.repeatX = false;
|
|
133
|
-
this.repeatY = true;
|
|
134
|
-
break;
|
|
135
|
-
default : // "repeat"
|
|
136
|
-
this.repeatX = true;
|
|
137
|
-
this.repeatY = true;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
this.resize(game.viewport.width, game.viewport.height);
|
|
141
|
-
this.createPattern();
|
|
142
|
-
},
|
|
143
|
-
configurable: true
|
|
144
|
-
});
|
|
145
|
-
|
|
146
100
|
this.repeat = settings.repeat || "repeat";
|
|
147
101
|
|
|
148
102
|
// on context lost, all previous textures are destroyed
|
|
149
|
-
event.
|
|
150
|
-
}
|
|
103
|
+
event.on(event.WEBGL_ONCONTEXT_RESTORED, this.createPattern, this);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Define if and how an Image Layer should be repeated.<br>
|
|
108
|
+
* By default, an Image Layer is repeated both vertically and horizontally.<br>
|
|
109
|
+
* Acceptable values : <br>
|
|
110
|
+
* * 'repeat' - The background image will be repeated both vertically and horizontally <br>
|
|
111
|
+
* * 'repeat-x' - The background image will be repeated only horizontally.<br>
|
|
112
|
+
* * 'repeat-y' - The background image will be repeated only vertically.<br>
|
|
113
|
+
* * 'no-repeat' - The background-image will not be repeated.<br>
|
|
114
|
+
* @public
|
|
115
|
+
* @type String
|
|
116
|
+
* @default 'repeat'
|
|
117
|
+
* @name me.ImageLayer#repeat
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @ignore
|
|
122
|
+
*/
|
|
123
|
+
get repeat() {
|
|
124
|
+
return this._repeat;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @ignore
|
|
129
|
+
*/
|
|
130
|
+
set repeat(value) {
|
|
131
|
+
this._repeat = value;
|
|
132
|
+
switch (this._repeat) {
|
|
133
|
+
case "no-repeat" :
|
|
134
|
+
this.repeatX = false;
|
|
135
|
+
this.repeatY = false;
|
|
136
|
+
break;
|
|
137
|
+
case "repeat-x" :
|
|
138
|
+
this.repeatX = true;
|
|
139
|
+
this.repeatY = false;
|
|
140
|
+
break;
|
|
141
|
+
case "repeat-y" :
|
|
142
|
+
this.repeatX = false;
|
|
143
|
+
this.repeatY = true;
|
|
144
|
+
break;
|
|
145
|
+
default : // "repeat"
|
|
146
|
+
this.repeatX = true;
|
|
147
|
+
this.repeatY = true;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
this.resize(viewport.width, viewport.height);
|
|
151
|
+
this.createPattern();
|
|
152
|
+
}
|
|
153
|
+
|
|
151
154
|
|
|
152
155
|
// called when the layer is added to the game world or a container
|
|
153
|
-
onActivateEvent
|
|
154
|
-
var _updateLayerFn = this.updateLayer.bind(this);
|
|
156
|
+
onActivateEvent() {
|
|
155
157
|
// register to the viewport change notification
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
event.on(event.VIEWPORT_ONCHANGE, this.updateLayer, this);
|
|
159
|
+
event.on(event.VIEWPORT_ONRESIZE, this.resize, this);
|
|
160
|
+
// force a first refresh when the level is loaded
|
|
161
|
+
event.once(event.LEVEL_LOADED, () => {
|
|
162
|
+
this.updateLayer(viewport.pos);
|
|
161
163
|
});
|
|
162
164
|
// in case the level is not added to the root container,
|
|
163
165
|
// the onActivateEvent call happens after the LEVEL_LOADED event
|
|
164
166
|
// so we need to force a first update
|
|
165
167
|
if (this.ancestor.root !== true) {
|
|
166
|
-
this.updateLayer(
|
|
168
|
+
this.updateLayer(viewport.pos);
|
|
167
169
|
}
|
|
168
|
-
}
|
|
170
|
+
}
|
|
169
171
|
|
|
170
172
|
/**
|
|
171
173
|
* resize the Image Layer to match the given size
|
|
@@ -175,28 +177,28 @@ var ImageLayer = Sprite.extend({
|
|
|
175
177
|
* @param {Number} w new width
|
|
176
178
|
* @param {Number} h new height
|
|
177
179
|
*/
|
|
178
|
-
resize
|
|
179
|
-
|
|
180
|
+
resize(w, h) {
|
|
181
|
+
super.resize(
|
|
180
182
|
this.repeatX ? Infinity : w,
|
|
181
183
|
this.repeatY ? Infinity : h
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
+
);
|
|
185
|
+
}
|
|
184
186
|
|
|
185
187
|
/**
|
|
186
188
|
* createPattern function
|
|
187
189
|
* @ignore
|
|
188
190
|
* @function
|
|
189
191
|
*/
|
|
190
|
-
createPattern
|
|
191
|
-
this._pattern =
|
|
192
|
-
}
|
|
192
|
+
createPattern() {
|
|
193
|
+
this._pattern = renderer.createPattern(this.image, this._repeat);
|
|
194
|
+
}
|
|
193
195
|
|
|
194
196
|
/**
|
|
195
197
|
* updateLayer function
|
|
196
198
|
* @ignore
|
|
197
199
|
* @function
|
|
198
200
|
*/
|
|
199
|
-
updateLayer
|
|
201
|
+
updateLayer(vpos) {
|
|
200
202
|
var rx = this.ratio.x,
|
|
201
203
|
ry = this.ratio.y;
|
|
202
204
|
|
|
@@ -205,8 +207,7 @@ var ImageLayer = Sprite.extend({
|
|
|
205
207
|
return;
|
|
206
208
|
}
|
|
207
209
|
|
|
208
|
-
var
|
|
209
|
-
width = this.width,
|
|
210
|
+
var width = this.width,
|
|
210
211
|
height = this.height,
|
|
211
212
|
bw = viewport.bounds.width,
|
|
212
213
|
bh = viewport.bounds.height,
|
|
@@ -238,14 +239,14 @@ var ImageLayer = Sprite.extend({
|
|
|
238
239
|
else {
|
|
239
240
|
this.pos.y = y;
|
|
240
241
|
}
|
|
241
|
-
}
|
|
242
|
+
}
|
|
242
243
|
|
|
243
244
|
/*
|
|
244
245
|
* override the default predraw function
|
|
245
246
|
* as repeat and anchor are managed directly in the draw method
|
|
246
247
|
* @ignore
|
|
247
248
|
*/
|
|
248
|
-
preDraw
|
|
249
|
+
preDraw(renderer) {
|
|
249
250
|
// save the context
|
|
250
251
|
renderer.save();
|
|
251
252
|
// apply the defined alpha value
|
|
@@ -253,15 +254,14 @@ var ImageLayer = Sprite.extend({
|
|
|
253
254
|
|
|
254
255
|
// apply the defined tint, if any
|
|
255
256
|
renderer.setTint(this.tint);
|
|
256
|
-
}
|
|
257
|
+
}
|
|
257
258
|
|
|
258
259
|
/**
|
|
259
260
|
* draw the image layer
|
|
260
261
|
* @ignore
|
|
261
262
|
*/
|
|
262
|
-
draw
|
|
263
|
-
var
|
|
264
|
-
width = this.width,
|
|
263
|
+
draw(renderer) {
|
|
264
|
+
var width = this.width,
|
|
265
265
|
height = this.height,
|
|
266
266
|
bw = viewport.bounds.width,
|
|
267
267
|
bh = viewport.bounds.height,
|
|
@@ -284,25 +284,26 @@ var ImageLayer = Sprite.extend({
|
|
|
284
284
|
viewport.width * 2,
|
|
285
285
|
viewport.height * 2
|
|
286
286
|
);
|
|
287
|
-
}
|
|
287
|
+
}
|
|
288
288
|
|
|
289
289
|
// called when the layer is removed from the game world or a container
|
|
290
|
-
onDeactivateEvent
|
|
290
|
+
onDeactivateEvent() {
|
|
291
291
|
// cancel all event subscriptions
|
|
292
|
-
event.
|
|
293
|
-
event.
|
|
294
|
-
|
|
295
|
-
},
|
|
292
|
+
event.off(event.VIEWPORT_ONCHANGE, this.updateLayer);
|
|
293
|
+
event.off(event.VIEWPORT_ONRESIZE, this.resize);
|
|
294
|
+
}
|
|
296
295
|
|
|
297
296
|
/**
|
|
298
297
|
* Destroy function<br>
|
|
299
298
|
* @ignore
|
|
300
299
|
*/
|
|
301
|
-
destroy
|
|
300
|
+
destroy() {
|
|
302
301
|
pool.push(this.ratio);
|
|
303
302
|
this.ratio = undefined;
|
|
304
|
-
|
|
303
|
+
event.off(event.WEBGL_ONCONTEXT_RESTORED, this.createPattern);
|
|
304
|
+
super.destroy();
|
|
305
305
|
}
|
|
306
|
-
|
|
306
|
+
|
|
307
|
+
};
|
|
307
308
|
|
|
308
309
|
export default ImageLayer;
|