melonjs 9.0.2 → 9.1.0
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 +3 -3
- package/dist/melonjs.js +40 -43
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.js +40 -43
- package/package.json +3 -3
- 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 +14 -0
- package/src/utils/string.js +2 -2
package/dist/melonjs.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v9.0
|
|
2
|
+
* melonJS Game Engine - v9.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -66,7 +66,7 @@ function trimRight(str) {
|
|
|
66
66
|
return str.replace(/\s+$/, "");
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
* returns true if the given string contains a numeric
|
|
69
|
+
* returns true if the given string contains a numeric integer or float value
|
|
70
70
|
* @public
|
|
71
71
|
* @function
|
|
72
72
|
* @memberOf me.utils.string
|
|
@@ -78,7 +78,7 @@ function isNumeric(str) {
|
|
|
78
78
|
if (typeof str === "string") {
|
|
79
79
|
str = str.trim();
|
|
80
80
|
}
|
|
81
|
-
return !isNaN(str) &&
|
|
81
|
+
return !isNaN(str) && /[+-]?([0-9]*[.])?[0-9]+/.test(str);
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* returns true if the given string contains a true or false
|
|
@@ -13429,7 +13429,8 @@ var Renderable = Rect.extend({
|
|
|
13429
13429
|
* <img src="images/anchor_point.png"/><br>
|
|
13430
13430
|
* a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.<br>
|
|
13431
13431
|
* <br>
|
|
13432
|
-
* <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation
|
|
13432
|
+
* <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
|
|
13433
|
+
* To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
|
|
13433
13434
|
* @public
|
|
13434
13435
|
* @type me.ObservableVector2d
|
|
13435
13436
|
* @default <0.5,0.5>
|
|
@@ -21035,6 +21036,15 @@ var Sprite = Renderable.extend({
|
|
|
21035
21036
|
this.textureAtlas = this.source.getAtlas();
|
|
21036
21037
|
}
|
|
21037
21038
|
|
|
21039
|
+
// throw an error if image ends up being null/undefined
|
|
21040
|
+
if (!this.image) {
|
|
21041
|
+
throw new Error((
|
|
21042
|
+
(typeof(settings.image) === "string") ?
|
|
21043
|
+
"'" + settings.image + "'" :
|
|
21044
|
+
"Image"
|
|
21045
|
+
) + " file for Image Layer '" + this.name + "' not found!");
|
|
21046
|
+
}
|
|
21047
|
+
|
|
21038
21048
|
// store/reset the current atlas information if specified
|
|
21039
21049
|
if (typeof(settings.atlas) !== "undefined") {
|
|
21040
21050
|
this.textureAtlas = settings.atlas;
|
|
@@ -21073,6 +21083,10 @@ var Sprite = Renderable.extend({
|
|
|
21073
21083
|
this.name = settings.name;
|
|
21074
21084
|
}
|
|
21075
21085
|
|
|
21086
|
+
// displaying order
|
|
21087
|
+
if (typeof settings.z !== "undefined") {
|
|
21088
|
+
this.pos.z = settings.z;
|
|
21089
|
+
}
|
|
21076
21090
|
// for sprite, addAnimation will return !=0
|
|
21077
21091
|
if (this.addAnimation("default", null) !== 0) {
|
|
21078
21092
|
// set as default
|
|
@@ -25805,10 +25819,14 @@ function readImageLayer(map, data, z) {
|
|
|
25805
25819
|
Object.assign({
|
|
25806
25820
|
name: data.name,
|
|
25807
25821
|
image: data.image,
|
|
25822
|
+
ratio : pool.pull("Vector2d", +data.parallaxx || 1.0, +data.parallaxy || 1.0),
|
|
25823
|
+
// convert to melonJS color format (note: this should be done earlier when parsing data)
|
|
25824
|
+
tint : typeof (data.tintcolor) !== "undefined" ? (pool.pull("Color")).parseHex(data.tintcolor, true) : undefined,
|
|
25808
25825
|
z: z
|
|
25809
25826
|
}, data.properties)
|
|
25810
25827
|
);
|
|
25811
25828
|
|
|
25829
|
+
|
|
25812
25830
|
// set some additional flags
|
|
25813
25831
|
var visible = typeof(data.visible) !== "undefined" ? data.visible : true;
|
|
25814
25832
|
imageLayer.setOpacity(visible ? +data.opacity : 0);
|
|
@@ -32355,10 +32373,10 @@ var plugin = {
|
|
|
32355
32373
|
* this can be overridden by the plugin
|
|
32356
32374
|
* @public
|
|
32357
32375
|
* @type String
|
|
32358
|
-
* @default "9.0
|
|
32376
|
+
* @default "9.1.0"
|
|
32359
32377
|
* @name me.plugin.Base#version
|
|
32360
32378
|
*/
|
|
32361
|
-
this.version = "9.0
|
|
32379
|
+
this.version = "9.1.0";
|
|
32362
32380
|
}
|
|
32363
32381
|
}),
|
|
32364
32382
|
|
|
@@ -34556,41 +34574,19 @@ var ColorLayer = Renderable.extend({
|
|
|
34556
34574
|
* repeat :"repeat-x"
|
|
34557
34575
|
* }), 1);
|
|
34558
34576
|
*/
|
|
34559
|
-
var ImageLayer =
|
|
34577
|
+
var ImageLayer = Sprite.extend({
|
|
34560
34578
|
/**
|
|
34561
34579
|
* @ignore
|
|
34562
34580
|
*/
|
|
34563
34581
|
init: function (x, y, settings) {
|
|
34564
34582
|
// call the constructor
|
|
34565
|
-
this._super(
|
|
34566
|
-
|
|
34567
|
-
// get the corresponding image
|
|
34568
|
-
this.image = (typeof settings.image === "object") ? settings.image : loader$1.getImage(settings.image);
|
|
34569
|
-
|
|
34570
|
-
// throw an error if image is null/undefined
|
|
34571
|
-
if (!this.image) {
|
|
34572
|
-
throw new Error((
|
|
34573
|
-
(typeof(settings.image) === "string") ?
|
|
34574
|
-
"'" + settings.image + "'" :
|
|
34575
|
-
"Image"
|
|
34576
|
-
) + " file for Image Layer '" + this.name + "' not found!");
|
|
34577
|
-
}
|
|
34578
|
-
|
|
34579
|
-
this.imagewidth = this.image.width;
|
|
34580
|
-
this.imageheight = this.image.height;
|
|
34581
|
-
|
|
34582
|
-
// set the sprite name if specified
|
|
34583
|
-
if (typeof (settings.name) === "string") {
|
|
34584
|
-
this.name = settings.name;
|
|
34585
|
-
}
|
|
34583
|
+
this._super(Sprite, "init", [x, y, settings]);
|
|
34586
34584
|
|
|
34587
34585
|
// render in screen coordinates
|
|
34588
34586
|
this.floating = true;
|
|
34589
34587
|
|
|
34590
|
-
//
|
|
34591
|
-
this.
|
|
34592
|
-
|
|
34593
|
-
this.offset = pool.pull("Vector2d", x, y);
|
|
34588
|
+
// image drawing offset
|
|
34589
|
+
this.offset.set(x, y);
|
|
34594
34590
|
|
|
34595
34591
|
/**
|
|
34596
34592
|
* Define the image scrolling ratio<br>
|
|
@@ -34608,8 +34604,8 @@ var ImageLayer = Renderable.extend({
|
|
|
34608
34604
|
|
|
34609
34605
|
if (typeof(settings.ratio) !== "undefined") {
|
|
34610
34606
|
// little hack for backward compatiblity
|
|
34611
|
-
if (
|
|
34612
|
-
this.ratio.set(settings.ratio, settings.ratio);
|
|
34607
|
+
if (utils$1.string.isNumeric(settings.ratio)) {
|
|
34608
|
+
this.ratio.set(settings.ratio, +settings.ratio);
|
|
34613
34609
|
} else /* vector */ {
|
|
34614
34610
|
this.ratio.setV(settings.ratio);
|
|
34615
34611
|
}
|
|
@@ -34725,7 +34721,7 @@ var ImageLayer = Renderable.extend({
|
|
|
34725
34721
|
* @param {Number} h new height
|
|
34726
34722
|
*/
|
|
34727
34723
|
resize : function (w, h) {
|
|
34728
|
-
this._super(
|
|
34724
|
+
this._super(Sprite, "resize", [
|
|
34729
34725
|
this.repeatX ? Infinity : w,
|
|
34730
34726
|
this.repeatY ? Infinity : h
|
|
34731
34727
|
]);
|
|
@@ -34755,8 +34751,8 @@ var ImageLayer = Renderable.extend({
|
|
|
34755
34751
|
}
|
|
34756
34752
|
|
|
34757
34753
|
var viewport = game$1.viewport,
|
|
34758
|
-
width = this.
|
|
34759
|
-
height = this.
|
|
34754
|
+
width = this.width,
|
|
34755
|
+
height = this.height,
|
|
34760
34756
|
bw = viewport.bounds.width,
|
|
34761
34757
|
bh = viewport.bounds.height,
|
|
34762
34758
|
ax = this.anchorPoint.x,
|
|
@@ -34799,6 +34795,9 @@ var ImageLayer = Renderable.extend({
|
|
|
34799
34795
|
renderer.save();
|
|
34800
34796
|
// apply the defined alpha value
|
|
34801
34797
|
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
|
|
34798
|
+
|
|
34799
|
+
// apply the defined tint, if any
|
|
34800
|
+
renderer.setTint(this.tint);
|
|
34802
34801
|
},
|
|
34803
34802
|
|
|
34804
34803
|
/**
|
|
@@ -34807,8 +34806,8 @@ var ImageLayer = Renderable.extend({
|
|
|
34807
34806
|
*/
|
|
34808
34807
|
draw : function (renderer) {
|
|
34809
34808
|
var viewport = game$1.viewport,
|
|
34810
|
-
width = this.
|
|
34811
|
-
height = this.
|
|
34809
|
+
width = this.width,
|
|
34810
|
+
height = this.height,
|
|
34812
34811
|
bw = viewport.bounds.width,
|
|
34813
34812
|
bh = viewport.bounds.height,
|
|
34814
34813
|
ax = this.anchorPoint.x,
|
|
@@ -34845,11 +34844,9 @@ var ImageLayer = Renderable.extend({
|
|
|
34845
34844
|
* @ignore
|
|
34846
34845
|
*/
|
|
34847
34846
|
destroy : function () {
|
|
34848
|
-
pool.push(this.offset);
|
|
34849
|
-
this.offset = undefined;
|
|
34850
34847
|
pool.push(this.ratio);
|
|
34851
34848
|
this.ratio = undefined;
|
|
34852
|
-
this._super(
|
|
34849
|
+
this._super(Sprite, "destroy");
|
|
34853
34850
|
}
|
|
34854
34851
|
});
|
|
34855
34852
|
|
|
@@ -36631,7 +36628,7 @@ var Jay = window.Jay;
|
|
|
36631
36628
|
* @name version
|
|
36632
36629
|
* @type {string}
|
|
36633
36630
|
*/
|
|
36634
|
-
const version = "9.0
|
|
36631
|
+
const version = "9.1.0";
|
|
36635
36632
|
|
|
36636
36633
|
|
|
36637
36634
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "melonjs",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.1.0",
|
|
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"
|
|
@@ -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
|
@@ -154,6 +154,15 @@ var Sprite = Renderable.extend({
|
|
|
154
154
|
this.textureAtlas = this.source.getAtlas();
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
// throw an error if image ends up being null/undefined
|
|
158
|
+
if (!this.image) {
|
|
159
|
+
throw new Error((
|
|
160
|
+
(typeof(settings.image) === "string") ?
|
|
161
|
+
"'" + settings.image + "'" :
|
|
162
|
+
"Image"
|
|
163
|
+
) + " file for Image Layer '" + this.name + "' not found!");
|
|
164
|
+
}
|
|
165
|
+
|
|
157
166
|
// store/reset the current atlas information if specified
|
|
158
167
|
if (typeof(settings.atlas) !== "undefined") {
|
|
159
168
|
this.textureAtlas = settings.atlas;
|
|
@@ -192,6 +201,11 @@ var Sprite = Renderable.extend({
|
|
|
192
201
|
this.name = settings.name;
|
|
193
202
|
}
|
|
194
203
|
|
|
204
|
+
// displaying order
|
|
205
|
+
if (typeof settings.z !== "undefined") {
|
|
206
|
+
this.pos.z = settings.z;
|
|
207
|
+
};
|
|
208
|
+
|
|
195
209
|
// for sprite, addAnimation will return !=0
|
|
196
210
|
if (this.addAnimation("default", null) !== 0) {
|
|
197
211
|
// set as default
|
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
|
/**
|