melonjs 9.0.1 → 9.1.2
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/README.md +9 -9
- package/dist/melonjs.js +74 -112
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.js +36716 -0
- package/package.json +4 -4
- package/src/level/tiled/TMXTileMap.js +4 -0
- package/src/renderable/imagelayer.js +17 -38
- package/src/renderable/renderable.js +2 -1
- package/src/renderable/sprite.js +9 -0
- package/src/shapes/poly.js +31 -0
- package/src/shapes/rectangle.js +0 -61
- package/src/system/device.js +6 -6
- package/src/utils/string.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "melonjs",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.1.2",
|
|
4
4
|
"description": "melonJS Game Engine",
|
|
5
5
|
"homepage": "http://www.melonjs.org/",
|
|
6
6
|
"keywords": [
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@rollup/plugin-commonjs": "^20.0.0",
|
|
61
61
|
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
62
62
|
"@rollup/plugin-replace": "^3.0.0",
|
|
63
|
-
"cheerio": "^1.0.0-rc.
|
|
63
|
+
"cheerio": "^1.0.0-rc.10",
|
|
64
64
|
"del-cli": "^4.0.1",
|
|
65
65
|
"eslint": "^7.32.0",
|
|
66
66
|
"ghpages": "0.0.10",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"karma-jasmine": "^4.0.1",
|
|
74
74
|
"karma-nyan-reporter": "0.2.5",
|
|
75
75
|
"qs": "^6.10.1",
|
|
76
|
-
"rollup": "^2.
|
|
76
|
+
"rollup": "^2.57.0",
|
|
77
77
|
"rollup-plugin-bundle-size": "^1.0.3",
|
|
78
78
|
"rollup-plugin-string": "^3.0.0",
|
|
79
79
|
"terser": "^5.8.0"
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"test": "npm run build && karma start tests/karma.conf.js",
|
|
87
87
|
"doc": "mkdirp docs && jsdoc -c jsdoc_conf.json",
|
|
88
88
|
"publishdoc": "npm run doc && ghpages melonjs/melonJS -p docs",
|
|
89
|
-
"release": "npm run dist && npm publish --access public
|
|
89
|
+
"release": "npm run dist && npm publish --access public",
|
|
90
90
|
"clean": "del-cli --force build/*.js docs"
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -71,10 +71,14 @@ function readImageLayer(map, data, z) {
|
|
|
71
71
|
Object.assign({
|
|
72
72
|
name: data.name,
|
|
73
73
|
image: data.image,
|
|
74
|
+
ratio : pool.pull("Vector2d", +data.parallaxx || 1.0, +data.parallaxy || 1.0),
|
|
75
|
+
// convert to melonJS color format (note: this should be done earlier when parsing data)
|
|
76
|
+
tint : typeof (data.tintcolor) !== "undefined" ? (pool.pull("Color")).parseHex(data.tintcolor, true) : undefined,
|
|
74
77
|
z: z
|
|
75
78
|
}, data.properties)
|
|
76
79
|
);
|
|
77
80
|
|
|
81
|
+
|
|
78
82
|
// set some additional flags
|
|
79
83
|
var visible = typeof(data.visible) !== "undefined" ? data.visible : true;
|
|
80
84
|
imageLayer.setOpacity(visible ? +data.opacity : 0);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import video from "./../video/video.js";
|
|
2
2
|
import event from "./../system/event.js";
|
|
3
3
|
import pool from "./../system/pooling.js";
|
|
4
|
-
import loader from "./../loader/loader.js";
|
|
5
4
|
import game from "./../game.js";
|
|
6
|
-
import
|
|
5
|
+
import Sprite from "./sprite.js";
|
|
6
|
+
import utils from "./../utils/utils.js";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -29,41 +29,19 @@ import Renderable from "./renderable.js";
|
|
|
29
29
|
* repeat :"repeat-x"
|
|
30
30
|
* }), 1);
|
|
31
31
|
*/
|
|
32
|
-
var ImageLayer =
|
|
32
|
+
var ImageLayer = Sprite.extend({
|
|
33
33
|
/**
|
|
34
34
|
* @ignore
|
|
35
35
|
*/
|
|
36
36
|
init: function (x, y, settings) {
|
|
37
37
|
// call the constructor
|
|
38
|
-
this._super(
|
|
39
|
-
|
|
40
|
-
// get the corresponding image
|
|
41
|
-
this.image = (typeof settings.image === "object") ? settings.image : loader.getImage(settings.image);
|
|
42
|
-
|
|
43
|
-
// throw an error if image is null/undefined
|
|
44
|
-
if (!this.image) {
|
|
45
|
-
throw new Error((
|
|
46
|
-
(typeof(settings.image) === "string") ?
|
|
47
|
-
"'" + settings.image + "'" :
|
|
48
|
-
"Image"
|
|
49
|
-
) + " file for Image Layer '" + this.name + "' not found!");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.imagewidth = this.image.width;
|
|
53
|
-
this.imageheight = this.image.height;
|
|
54
|
-
|
|
55
|
-
// set the sprite name if specified
|
|
56
|
-
if (typeof (settings.name) === "string") {
|
|
57
|
-
this.name = settings.name;
|
|
58
|
-
}
|
|
38
|
+
this._super(Sprite, "init", [x, y, settings]);
|
|
59
39
|
|
|
60
40
|
// render in screen coordinates
|
|
61
41
|
this.floating = true;
|
|
62
42
|
|
|
63
|
-
//
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
this.offset = pool.pull("Vector2d", x, y);
|
|
43
|
+
// image drawing offset
|
|
44
|
+
this.offset.set(x, y);
|
|
67
45
|
|
|
68
46
|
/**
|
|
69
47
|
* Define the image scrolling ratio<br>
|
|
@@ -81,8 +59,8 @@ var ImageLayer = Renderable.extend({
|
|
|
81
59
|
|
|
82
60
|
if (typeof(settings.ratio) !== "undefined") {
|
|
83
61
|
// little hack for backward compatiblity
|
|
84
|
-
if (
|
|
85
|
-
this.ratio.set(settings.ratio, settings.ratio);
|
|
62
|
+
if (utils.string.isNumeric(settings.ratio)) {
|
|
63
|
+
this.ratio.set(settings.ratio, +settings.ratio);
|
|
86
64
|
} else /* vector */ {
|
|
87
65
|
this.ratio.setV(settings.ratio);
|
|
88
66
|
}
|
|
@@ -198,7 +176,7 @@ var ImageLayer = Renderable.extend({
|
|
|
198
176
|
* @param {Number} h new height
|
|
199
177
|
*/
|
|
200
178
|
resize : function (w, h) {
|
|
201
|
-
this._super(
|
|
179
|
+
this._super(Sprite, "resize", [
|
|
202
180
|
this.repeatX ? Infinity : w,
|
|
203
181
|
this.repeatY ? Infinity : h
|
|
204
182
|
]);
|
|
@@ -228,8 +206,8 @@ var ImageLayer = Renderable.extend({
|
|
|
228
206
|
}
|
|
229
207
|
|
|
230
208
|
var viewport = game.viewport,
|
|
231
|
-
width = this.
|
|
232
|
-
height = this.
|
|
209
|
+
width = this.width,
|
|
210
|
+
height = this.height,
|
|
233
211
|
bw = viewport.bounds.width,
|
|
234
212
|
bh = viewport.bounds.height,
|
|
235
213
|
ax = this.anchorPoint.x,
|
|
@@ -272,6 +250,9 @@ var ImageLayer = Renderable.extend({
|
|
|
272
250
|
renderer.save();
|
|
273
251
|
// apply the defined alpha value
|
|
274
252
|
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
|
|
253
|
+
|
|
254
|
+
// apply the defined tint, if any
|
|
255
|
+
renderer.setTint(this.tint);
|
|
275
256
|
},
|
|
276
257
|
|
|
277
258
|
/**
|
|
@@ -280,8 +261,8 @@ var ImageLayer = Renderable.extend({
|
|
|
280
261
|
*/
|
|
281
262
|
draw : function (renderer) {
|
|
282
263
|
var viewport = game.viewport,
|
|
283
|
-
width = this.
|
|
284
|
-
height = this.
|
|
264
|
+
width = this.width,
|
|
265
|
+
height = this.height,
|
|
285
266
|
bw = viewport.bounds.width,
|
|
286
267
|
bh = viewport.bounds.height,
|
|
287
268
|
ax = this.anchorPoint.x,
|
|
@@ -318,11 +299,9 @@ var ImageLayer = Renderable.extend({
|
|
|
318
299
|
* @ignore
|
|
319
300
|
*/
|
|
320
301
|
destroy : function () {
|
|
321
|
-
pool.push(this.offset);
|
|
322
|
-
this.offset = undefined;
|
|
323
302
|
pool.push(this.ratio);
|
|
324
303
|
this.ratio = undefined;
|
|
325
|
-
this._super(
|
|
304
|
+
this._super(Sprite, "destroy");
|
|
326
305
|
}
|
|
327
306
|
});
|
|
328
307
|
|
|
@@ -169,7 +169,8 @@ var Renderable = Rect.extend({
|
|
|
169
169
|
* <img src="images/anchor_point.png"/><br>
|
|
170
170
|
* a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.<br>
|
|
171
171
|
* <br>
|
|
172
|
-
* <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation
|
|
172
|
+
* <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
|
|
173
|
+
* To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
|
|
173
174
|
* @public
|
|
174
175
|
* @type me.ObservableVector2d
|
|
175
176
|
* @default <0.5,0.5>
|
package/src/renderable/sprite.js
CHANGED
|
@@ -147,6 +147,10 @@ var Sprite = Renderable.extend({
|
|
|
147
147
|
} else {
|
|
148
148
|
// HTMLImageElement/Canvas or String
|
|
149
149
|
this.image = (typeof settings.image === "object") ? settings.image : loader.getImage(settings.image);
|
|
150
|
+
// throw an error if image ends up being null/undefined
|
|
151
|
+
if (!this.image) {
|
|
152
|
+
throw new Error("me.Sprite: '" + settings.image + "' image/texture not found!");
|
|
153
|
+
}
|
|
150
154
|
// update the default "current" frame size
|
|
151
155
|
this.current.width = settings.framewidth = settings.framewidth || this.image.width;
|
|
152
156
|
this.current.height = settings.frameheight = settings.frameheight || this.image.height;
|
|
@@ -192,6 +196,11 @@ var Sprite = Renderable.extend({
|
|
|
192
196
|
this.name = settings.name;
|
|
193
197
|
}
|
|
194
198
|
|
|
199
|
+
// displaying order
|
|
200
|
+
if (typeof settings.z !== "undefined") {
|
|
201
|
+
this.pos.z = settings.z;
|
|
202
|
+
};
|
|
203
|
+
|
|
195
204
|
// for sprite, addAnimation will return !=0
|
|
196
205
|
if (this.addAnimation("default", null) !== 0) {
|
|
197
206
|
// set as default
|
package/src/shapes/poly.js
CHANGED
|
@@ -330,6 +330,37 @@ var Polygon = window.Jay.extend({
|
|
|
330
330
|
return this;
|
|
331
331
|
},
|
|
332
332
|
|
|
333
|
+
/**
|
|
334
|
+
* Shifts the Polygon to the given position vector.
|
|
335
|
+
* @name shift
|
|
336
|
+
* @memberOf me.Polygon
|
|
337
|
+
* @function
|
|
338
|
+
* @param {me.Vector2d} position
|
|
339
|
+
*/
|
|
340
|
+
/**
|
|
341
|
+
* Shifts the Polygon to the given x, y position.
|
|
342
|
+
* @name shift
|
|
343
|
+
* @memberOf me.Polygon
|
|
344
|
+
* @function
|
|
345
|
+
* @param {Number} x
|
|
346
|
+
* @param {Number} y
|
|
347
|
+
*/
|
|
348
|
+
shift() {
|
|
349
|
+
var _x, _y;
|
|
350
|
+
if (arguments.length === 2) {
|
|
351
|
+
// x, y
|
|
352
|
+
_x = arguments[0];
|
|
353
|
+
_y = arguments[1];
|
|
354
|
+
} else {
|
|
355
|
+
// vector
|
|
356
|
+
_x = arguments[0].x;
|
|
357
|
+
_y = arguments[0].y;
|
|
358
|
+
}
|
|
359
|
+
this.pos.x = _x;
|
|
360
|
+
this.pos.y = _y;
|
|
361
|
+
this.updateBounds();
|
|
362
|
+
},
|
|
363
|
+
|
|
333
364
|
/**
|
|
334
365
|
* Returns true if the polygon contains the given point.
|
|
335
366
|
* (Note: it is highly recommended to first do a hit test on the corresponding <br>
|
package/src/shapes/rectangle.js
CHANGED
|
@@ -113,67 +113,6 @@ var Rect = Polygon.extend({
|
|
|
113
113
|
return this.setShape(rect.pos.x, rect.pos.y, rect.width, rect.height);
|
|
114
114
|
},
|
|
115
115
|
|
|
116
|
-
/**
|
|
117
|
-
* translate the rect by the specified offset
|
|
118
|
-
* @name translate
|
|
119
|
-
* @memberOf me.Rect.prototype
|
|
120
|
-
* @function
|
|
121
|
-
* @param {Number} x x offset
|
|
122
|
-
* @param {Number} y y offset
|
|
123
|
-
* @return {me.Rect} this rectangle
|
|
124
|
-
*/
|
|
125
|
-
/**
|
|
126
|
-
* translate the rect by the specified vector
|
|
127
|
-
* @name translate
|
|
128
|
-
* @memberOf me.Rect.prototype
|
|
129
|
-
* @function
|
|
130
|
-
* @param {me.Vector2d} v vector offset
|
|
131
|
-
* @return {me.Rect} this rectangle
|
|
132
|
-
*/
|
|
133
|
-
translate : function () {
|
|
134
|
-
var _x, _y;
|
|
135
|
-
|
|
136
|
-
if (arguments.length === 2) {
|
|
137
|
-
// x, y
|
|
138
|
-
_x = arguments[0];
|
|
139
|
-
_y = arguments[1];
|
|
140
|
-
} else {
|
|
141
|
-
// vector
|
|
142
|
-
_x = arguments[0].x;
|
|
143
|
-
_y = arguments[0].y;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
this.pos.x += _x;
|
|
147
|
-
this.pos.y += _y;
|
|
148
|
-
|
|
149
|
-
return this;
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Shifts the rect to the given position vector.
|
|
154
|
-
* @name shift
|
|
155
|
-
* @memberOf me.Rect
|
|
156
|
-
* @function
|
|
157
|
-
* @param {me.Vector2d} position
|
|
158
|
-
*/
|
|
159
|
-
/**
|
|
160
|
-
* Shifts the rect to the given x, y position.
|
|
161
|
-
* @name shift
|
|
162
|
-
* @memberOf me.Rect
|
|
163
|
-
* @function
|
|
164
|
-
* @param {Number} x
|
|
165
|
-
* @param {Number} y
|
|
166
|
-
*/
|
|
167
|
-
shift : function () {
|
|
168
|
-
if (arguments.length === 2) {
|
|
169
|
-
// x, y
|
|
170
|
-
this.pos.set(arguments[0], arguments[1]);
|
|
171
|
-
} else {
|
|
172
|
-
// vector
|
|
173
|
-
this.pos.setV(arguments[0]);
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
|
|
177
116
|
/**
|
|
178
117
|
* merge this rectangle with another one
|
|
179
118
|
* @name union
|
package/src/system/device.js
CHANGED
|
@@ -142,16 +142,16 @@ let device = {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
// set pause/stop action on losing focus
|
|
145
|
-
window.addEventListener("blur", function () {
|
|
145
|
+
window.addEventListener("blur", (function () {
|
|
146
146
|
if (this.stopOnBlur) {
|
|
147
147
|
state.stop(true);
|
|
148
148
|
}
|
|
149
149
|
if (this.pauseOnBlur) {
|
|
150
150
|
state.pause(true);
|
|
151
151
|
}
|
|
152
|
-
}, false);
|
|
152
|
+
}).bind(this), false);
|
|
153
153
|
// set restart/resume action on gaining focus
|
|
154
|
-
window.addEventListener("focus", function () {
|
|
154
|
+
window.addEventListener("focus", (function () {
|
|
155
155
|
if (this.stopOnBlur) {
|
|
156
156
|
state.restart(true);
|
|
157
157
|
}
|
|
@@ -162,7 +162,7 @@ let device = {
|
|
|
162
162
|
if (this.autoFocus) {
|
|
163
163
|
this.focus();
|
|
164
164
|
}
|
|
165
|
-
}, false);
|
|
165
|
+
}).bind(this), false);
|
|
166
166
|
|
|
167
167
|
|
|
168
168
|
// Set the name of the hidden property and the change event for visibility
|
|
@@ -186,7 +186,7 @@ let device = {
|
|
|
186
186
|
if (typeof (visibilityChange) === "string") {
|
|
187
187
|
// add the corresponding event listener
|
|
188
188
|
document.addEventListener(visibilityChange,
|
|
189
|
-
function () {
|
|
189
|
+
(function () {
|
|
190
190
|
if (document[hidden]) {
|
|
191
191
|
if (this.stopOnBlur) {
|
|
192
192
|
state.stop(true);
|
|
@@ -202,7 +202,7 @@ let device = {
|
|
|
202
202
|
state.resume(true);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
}, false
|
|
205
|
+
}).bind(this), false
|
|
206
206
|
);
|
|
207
207
|
}
|
|
208
208
|
},
|
package/src/utils/string.js
CHANGED
|
@@ -45,7 +45,7 @@ export function trimRight(str) {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* returns true if the given string contains a numeric
|
|
48
|
+
* returns true if the given string contains a numeric integer or float value
|
|
49
49
|
* @public
|
|
50
50
|
* @function
|
|
51
51
|
* @memberOf me.utils.string
|
|
@@ -57,7 +57,7 @@ export function isNumeric(str) {
|
|
|
57
57
|
if (typeof str === "string") {
|
|
58
58
|
str = str.trim();
|
|
59
59
|
}
|
|
60
|
-
return !isNaN(str) &&
|
|
60
|
+
return !isNaN(str) && /[+-]?([0-9]*[.])?[0-9]+/.test(str);
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
/**
|