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 CHANGED
@@ -45,9 +45,9 @@ and currently features :
45
45
  - Uncompressed Plain, Base64, CSV and JSON encoded XML tilemap loading
46
46
  - Orthogonal, Isometric and Hexagonal maps (both normal and staggered)
47
47
  - Multiple layers (multiple background/foreground, collision and Image layers)
48
- - Multiple Tileset support
49
- - Tileset Transparency settings
50
- - Layers Alpha settings
48
+ - Animated and multiple Tileset support
49
+ - Tileset transparency settings
50
+ - Layers alpha and tinting settings
51
51
  - Rectangle, Ellipse, Polygon and Polyline objects support
52
52
  - Tiled Objects
53
53
  - Flipped & rotated Tiles
@@ -68,7 +68,7 @@ Using melonJS
68
68
  Basic Example
69
69
 
70
70
  ```JavaScript
71
- import * as me from "melonjs-module.js"
71
+ import * as me from "melonjs.module.js";
72
72
 
73
73
  me.device.onReady(function () {
74
74
  // initialize the display canvas once the device/browser is ready
@@ -118,7 +118,7 @@ Since version 9.0.0 melonJS provides different build options :
118
118
  | ------------------- | ----------- |
119
119
  | `melonjs.js` | a legacy ES5 UMD Bundle (directly transpiled from the ES6 version) including full API backward compatibility with previous versions |
120
120
  | `melonjs.min.js` | a minified version of the ES5 UMD bundle version |
121
- | `melonjs-module.js` | a ES6 Module Bundle, for those living on the edge, and with no backward compatibility (note: this will break your game when upgrading!) |
121
+ | `melonjs.module.js` | a ES6 Module Bundle, for those living on the edge, and with no backward compatibility (note: this will break your game when upgrading!) |
122
122
 
123
123
  > Note: current version of both the tutorials and the debugPanel are not compatible with the ES6 version.
124
124
 
@@ -126,9 +126,9 @@ Alternatively, the latest version of melonJS can be installed through [NPM](http
126
126
 
127
127
  $ npm install melonjs
128
128
 
129
- If you need to import the ES6 module of melonjs :
129
+ If you need to import the ES6 module of melonjs (for Webpack):
130
130
 
131
- $ import * as me from "melonjs-module.js";
131
+ $ import * as me from 'melonjs/dist/melonjs.module.js';
132
132
 
133
133
  > Note: when using the es6 module, deprecated methods need to be manually applied, see [here](http://melonjs.github.io/melonJS/docs/me.deprecated.html#.apply)
134
134
 
@@ -138,7 +138,7 @@ Or can simply be added to your html, through a content delivery network (CDN) UR
138
138
  <!-- load the ES5 UMD bundle of melonJS v9.0.0 -->
139
139
  <script src="https://cdn.jsdelivr.net/npm/melonjs@9.0.0/dist/melonjs.js"></script>
140
140
  <!-- load the ES6 module bundle of melonJS v9.0.0 -->
141
- <script src="https://cdn.jsdelivr.net/npm/melonjs@9.0.0/dist/melonjs-module.js"></script>
141
+ <script src="https://cdn.jsdelivr.net/npm/melonjs@9.0.0/dist/melonjs.module.js"></script>
142
142
  <!-- omit the version completely to get the latest one -->
143
143
  <!-- you should NOT use this in production -->
144
144
  <script src="https://cdn.jsdelivr.net/npm/melonjs/dist/melonjs.js"></script>
@@ -176,7 +176,7 @@ Then build the melonJS source by running:
176
176
  The generated library will be available under the `build` directory :
177
177
  - `melonjs.js` : plain ES5 UMD bundle
178
178
  - `melonjs.min.js` : minified ES5 UMD bundle
179
- - `melonjs-module.js` : plain ES6 module
179
+ - `melonjs.module.js` : plain ES6 module
180
180
 
181
181
  To run the melonJS test suite simply use the following:
182
182
 
package/dist/melonjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v9.0.1
2
+ * melonJS Game Engine - v9.1.2
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -9,7 +9,7 @@
9
9
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
10
10
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
11
11
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.me = {}));
12
- }(this, (function (exports) { 'use strict';
12
+ })(this, (function (exports) { 'use strict';
13
13
 
14
14
  /* eslint-disable no-global-assign, no-native-reassign */
15
15
  if (typeof console === "undefined") {
@@ -72,7 +72,7 @@
72
72
  return str.replace(/\s+$/, "");
73
73
  }
74
74
  /**
75
- * returns true if the given string contains a numeric (integer) value
75
+ * returns true if the given string contains a numeric integer or float value
76
76
  * @public
77
77
  * @function
78
78
  * @memberOf me.utils.string
@@ -84,7 +84,7 @@
84
84
  if (typeof str === "string") {
85
85
  str = str.trim();
86
86
  }
87
- return !isNaN(str) && /^\d+$/.test(str);
87
+ return !isNaN(str) && /[+-]?([0-9]*[.])?[0-9]+/.test(str);
88
88
  }
89
89
  /**
90
90
  * returns true if the given string contains a true or false
@@ -10681,6 +10681,37 @@
10681
10681
  return this;
10682
10682
  },
10683
10683
 
10684
+ /**
10685
+ * Shifts the Polygon to the given position vector.
10686
+ * @name shift
10687
+ * @memberOf me.Polygon
10688
+ * @function
10689
+ * @param {me.Vector2d} position
10690
+ */
10691
+ /**
10692
+ * Shifts the Polygon to the given x, y position.
10693
+ * @name shift
10694
+ * @memberOf me.Polygon
10695
+ * @function
10696
+ * @param {Number} x
10697
+ * @param {Number} y
10698
+ */
10699
+ shift: function shift() {
10700
+ var _x, _y;
10701
+ if (arguments.length === 2) {
10702
+ // x, y
10703
+ _x = arguments[0];
10704
+ _y = arguments[1];
10705
+ } else {
10706
+ // vector
10707
+ _x = arguments[0].x;
10708
+ _y = arguments[0].y;
10709
+ }
10710
+ this.pos.x = _x;
10711
+ this.pos.y = _y;
10712
+ this.updateBounds();
10713
+ },
10714
+
10684
10715
  /**
10685
10716
  * Returns true if the polygon contains the given point.
10686
10717
  * (Note: it is highly recommended to first do a hit test on the corresponding <br>
@@ -10892,67 +10923,6 @@
10892
10923
  return this.setShape(rect.pos.x, rect.pos.y, rect.width, rect.height);
10893
10924
  },
10894
10925
 
10895
- /**
10896
- * translate the rect by the specified offset
10897
- * @name translate
10898
- * @memberOf me.Rect.prototype
10899
- * @function
10900
- * @param {Number} x x offset
10901
- * @param {Number} y y offset
10902
- * @return {me.Rect} this rectangle
10903
- */
10904
- /**
10905
- * translate the rect by the specified vector
10906
- * @name translate
10907
- * @memberOf me.Rect.prototype
10908
- * @function
10909
- * @param {me.Vector2d} v vector offset
10910
- * @return {me.Rect} this rectangle
10911
- */
10912
- translate : function () {
10913
- var _x, _y;
10914
-
10915
- if (arguments.length === 2) {
10916
- // x, y
10917
- _x = arguments[0];
10918
- _y = arguments[1];
10919
- } else {
10920
- // vector
10921
- _x = arguments[0].x;
10922
- _y = arguments[0].y;
10923
- }
10924
-
10925
- this.pos.x += _x;
10926
- this.pos.y += _y;
10927
-
10928
- return this;
10929
- },
10930
-
10931
- /**
10932
- * Shifts the rect to the given position vector.
10933
- * @name shift
10934
- * @memberOf me.Rect
10935
- * @function
10936
- * @param {me.Vector2d} position
10937
- */
10938
- /**
10939
- * Shifts the rect to the given x, y position.
10940
- * @name shift
10941
- * @memberOf me.Rect
10942
- * @function
10943
- * @param {Number} x
10944
- * @param {Number} y
10945
- */
10946
- shift : function () {
10947
- if (arguments.length === 2) {
10948
- // x, y
10949
- this.pos.set(arguments[0], arguments[1]);
10950
- } else {
10951
- // vector
10952
- this.pos.setV(arguments[0]);
10953
- }
10954
- },
10955
-
10956
10926
  /**
10957
10927
  * merge this rectangle with another one
10958
10928
  * @name union
@@ -13533,7 +13503,8 @@
13533
13503
  * <img src="images/anchor_point.png"/><br>
13534
13504
  * a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.<br>
13535
13505
  * <br>
13536
- * <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation</i>
13506
+ * <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
13507
+ * To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
13537
13508
  * @public
13538
13509
  * @type me.ObservableVector2d
13539
13510
  * @default <0.5,0.5>
@@ -21153,6 +21124,10 @@
21153
21124
  } else {
21154
21125
  // HTMLImageElement/Canvas or String
21155
21126
  this.image = (typeof settings.image === "object") ? settings.image : loader$1.getImage(settings.image);
21127
+ // throw an error if image ends up being null/undefined
21128
+ if (!this.image) {
21129
+ throw new Error("me.Sprite: '" + settings.image + "' image/texture not found!");
21130
+ }
21156
21131
  // update the default "current" frame size
21157
21132
  this.current.width = settings.framewidth = settings.framewidth || this.image.width;
21158
21133
  this.current.height = settings.frameheight = settings.frameheight || this.image.height;
@@ -21198,6 +21173,10 @@
21198
21173
  this.name = settings.name;
21199
21174
  }
21200
21175
 
21176
+ // displaying order
21177
+ if (typeof settings.z !== "undefined") {
21178
+ this.pos.z = settings.z;
21179
+ }
21201
21180
  // for sprite, addAnimation will return !=0
21202
21181
  if (this.addAnimation("default", null) !== 0) {
21203
21182
  // set as default
@@ -25943,10 +25922,14 @@
25943
25922
  Object.assign({
25944
25923
  name: data.name,
25945
25924
  image: data.image,
25925
+ ratio : pool.pull("Vector2d", +data.parallaxx || 1.0, +data.parallaxy || 1.0),
25926
+ // convert to melonJS color format (note: this should be done earlier when parsing data)
25927
+ tint : typeof (data.tintcolor) !== "undefined" ? (pool.pull("Color")).parseHex(data.tintcolor, true) : undefined,
25946
25928
  z: z
25947
25929
  }, data.properties)
25948
25930
  );
25949
25931
 
25932
+
25950
25933
  // set some additional flags
25951
25934
  var visible = typeof(data.visible) !== "undefined" ? data.visible : true;
25952
25935
  imageLayer.setOpacity(visible ? +data.opacity : 0);
@@ -28391,16 +28374,16 @@
28391
28374
  }
28392
28375
 
28393
28376
  // set pause/stop action on losing focus
28394
- window.addEventListener("blur", function () {
28377
+ window.addEventListener("blur", (function () {
28395
28378
  if (this.stopOnBlur) {
28396
28379
  state$1.stop(true);
28397
28380
  }
28398
28381
  if (this.pauseOnBlur) {
28399
28382
  state$1.pause(true);
28400
28383
  }
28401
- }, false);
28384
+ }).bind(this), false);
28402
28385
  // set restart/resume action on gaining focus
28403
- window.addEventListener("focus", function () {
28386
+ window.addEventListener("focus", (function () {
28404
28387
  if (this.stopOnBlur) {
28405
28388
  state$1.restart(true);
28406
28389
  }
@@ -28411,7 +28394,7 @@
28411
28394
  if (this.autoFocus) {
28412
28395
  this.focus();
28413
28396
  }
28414
- }, false);
28397
+ }).bind(this), false);
28415
28398
 
28416
28399
 
28417
28400
  // Set the name of the hidden property and the change event for visibility
@@ -28435,7 +28418,7 @@
28435
28418
  if (typeof (visibilityChange) === "string") {
28436
28419
  // add the corresponding event listener
28437
28420
  document.addEventListener(visibilityChange,
28438
- function () {
28421
+ (function () {
28439
28422
  if (document[hidden]) {
28440
28423
  if (this.stopOnBlur) {
28441
28424
  state$1.stop(true);
@@ -28451,7 +28434,7 @@
28451
28434
  state$1.resume(true);
28452
28435
  }
28453
28436
  }
28454
- }, false
28437
+ }).bind(this), false
28455
28438
  );
28456
28439
  }
28457
28440
  },
@@ -32506,10 +32489,10 @@
32506
32489
  * this can be overridden by the plugin
32507
32490
  * @public
32508
32491
  * @type String
32509
- * @default "9.0.1"
32492
+ * @default "9.1.2"
32510
32493
  * @name me.plugin.Base#version
32511
32494
  */
32512
- this.version = "9.0.1";
32495
+ this.version = "9.1.2";
32513
32496
  }
32514
32497
  }),
32515
32498
 
@@ -34706,41 +34689,19 @@
34706
34689
  * repeat :"repeat-x"
34707
34690
  * }), 1);
34708
34691
  */
34709
- var ImageLayer = Renderable.extend({
34692
+ var ImageLayer = Sprite.extend({
34710
34693
  /**
34711
34694
  * @ignore
34712
34695
  */
34713
34696
  init: function (x, y, settings) {
34714
34697
  // call the constructor
34715
- this._super(Renderable, "init", [x, y, Infinity, Infinity]);
34716
-
34717
- // get the corresponding image
34718
- this.image = (typeof settings.image === "object") ? settings.image : loader$1.getImage(settings.image);
34719
-
34720
- // throw an error if image is null/undefined
34721
- if (!this.image) {
34722
- throw new Error((
34723
- (typeof(settings.image) === "string") ?
34724
- "'" + settings.image + "'" :
34725
- "Image"
34726
- ) + " file for Image Layer '" + this.name + "' not found!");
34727
- }
34728
-
34729
- this.imagewidth = this.image.width;
34730
- this.imageheight = this.image.height;
34731
-
34732
- // set the sprite name if specified
34733
- if (typeof (settings.name) === "string") {
34734
- this.name = settings.name;
34735
- }
34698
+ this._super(Sprite, "init", [x, y, settings]);
34736
34699
 
34737
34700
  // render in screen coordinates
34738
34701
  this.floating = true;
34739
34702
 
34740
- // displaying order
34741
- this.pos.z = settings.z || 0;
34742
-
34743
- this.offset = pool.pull("Vector2d", x, y);
34703
+ // image drawing offset
34704
+ this.offset.set(x, y);
34744
34705
 
34745
34706
  /**
34746
34707
  * Define the image scrolling ratio<br>
@@ -34758,8 +34719,8 @@
34758
34719
 
34759
34720
  if (typeof(settings.ratio) !== "undefined") {
34760
34721
  // little hack for backward compatiblity
34761
- if (typeof(settings.ratio) === "number") {
34762
- this.ratio.set(settings.ratio, settings.ratio);
34722
+ if (utils$1.string.isNumeric(settings.ratio)) {
34723
+ this.ratio.set(settings.ratio, +settings.ratio);
34763
34724
  } else /* vector */ {
34764
34725
  this.ratio.setV(settings.ratio);
34765
34726
  }
@@ -34875,7 +34836,7 @@
34875
34836
  * @param {Number} h new height
34876
34837
  */
34877
34838
  resize : function (w, h) {
34878
- this._super(Renderable, "resize", [
34839
+ this._super(Sprite, "resize", [
34879
34840
  this.repeatX ? Infinity : w,
34880
34841
  this.repeatY ? Infinity : h
34881
34842
  ]);
@@ -34905,8 +34866,8 @@
34905
34866
  }
34906
34867
 
34907
34868
  var viewport = game$1.viewport,
34908
- width = this.imagewidth,
34909
- height = this.imageheight,
34869
+ width = this.width,
34870
+ height = this.height,
34910
34871
  bw = viewport.bounds.width,
34911
34872
  bh = viewport.bounds.height,
34912
34873
  ax = this.anchorPoint.x,
@@ -34949,6 +34910,9 @@
34949
34910
  renderer.save();
34950
34911
  // apply the defined alpha value
34951
34912
  renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
34913
+
34914
+ // apply the defined tint, if any
34915
+ renderer.setTint(this.tint);
34952
34916
  },
34953
34917
 
34954
34918
  /**
@@ -34957,8 +34921,8 @@
34957
34921
  */
34958
34922
  draw : function (renderer) {
34959
34923
  var viewport = game$1.viewport,
34960
- width = this.imagewidth,
34961
- height = this.imageheight,
34924
+ width = this.width,
34925
+ height = this.height,
34962
34926
  bw = viewport.bounds.width,
34963
34927
  bh = viewport.bounds.height,
34964
34928
  ax = this.anchorPoint.x,
@@ -34995,11 +34959,9 @@
34995
34959
  * @ignore
34996
34960
  */
34997
34961
  destroy : function () {
34998
- pool.push(this.offset);
34999
- this.offset = undefined;
35000
34962
  pool.push(this.ratio);
35001
34963
  this.ratio = undefined;
35002
- this._super(Renderable, "destroy");
34964
+ this._super(Sprite, "destroy");
35003
34965
  }
35004
34966
  });
35005
34967
 
@@ -36781,7 +36743,7 @@
36781
36743
  * @name version
36782
36744
  * @type {string}
36783
36745
  */
36784
- var version = "9.0.1";
36746
+ var version = "9.1.2";
36785
36747
 
36786
36748
 
36787
36749
  /**
@@ -36976,5 +36938,5 @@
36976
36938
 
36977
36939
  Object.defineProperty(exports, '__esModule', { value: true });
36978
36940
 
36979
- })));
36941
+ }));
36980
36942
  me.deprecated.apply();