melonjs 10.2.3 → 10.5.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 +6 -6
- package/dist/melonjs.js +3620 -3582
- package/dist/melonjs.min.js +5 -5
- package/dist/melonjs.module.d.ts +3646 -4545
- package/dist/melonjs.module.js +3912 -3521
- package/package.json +21 -20
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/entity.js +32 -38
- package/src/game.js +21 -22
- package/src/{shapes → geometries}/ellipse.js +40 -47
- package/src/{shapes → geometries}/line.js +9 -12
- package/src/{shapes → geometries}/poly.js +100 -53
- package/src/{shapes → geometries}/rectangle.js +42 -45
- package/src/index.js +14 -32
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +61 -29
- package/src/input/pointerevent.js +92 -29
- package/src/lang/deprecated.js +83 -13
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -9
- package/src/level/tiled/TMXLayer.js +30 -33
- package/src/level/tiled/TMXObject.js +59 -53
- package/src/level/tiled/TMXTile.js +18 -19
- package/src/level/tiled/TMXTileMap.js +40 -46
- package/src/level/tiled/TMXTileset.js +12 -16
- package/src/level/tiled/TMXTilesetGroup.js +9 -10
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
- package/src/level/tiled/renderer/TMXRenderer.js +24 -26
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
- package/src/loader/loader.js +17 -16
- package/src/loader/loadingscreen.js +2 -5
- package/src/math/color.js +47 -67
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -59
- package/src/math/matrix3.js +56 -63
- package/src/math/observable_vector2.js +87 -77
- package/src/math/observable_vector3.js +97 -80
- package/src/math/vector2.js +107 -97
- package/src/math/vector3.js +116 -100
- package/src/particles/emitter.js +66 -76
- package/src/particles/particle.js +4 -6
- package/src/particles/particlecontainer.js +2 -4
- package/src/physics/body.js +49 -147
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -20
- package/src/physics/sat.js +30 -30
- package/src/physics/world.js +24 -29
- package/src/plugin/plugin.js +11 -15
- package/src/renderable/GUI.js +41 -47
- package/src/renderable/collectable.js +5 -10
- package/src/renderable/colorlayer.js +10 -15
- package/src/renderable/container.js +87 -73
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -32
- package/src/renderable/nineslicesprite.js +41 -42
- package/src/renderable/renderable.js +113 -124
- package/src/renderable/sprite.js +62 -69
- package/src/renderable/trigger.js +26 -32
- package/src/state/stage.js +13 -18
- package/src/state/state.js +26 -27
- package/src/system/device.js +76 -133
- package/src/system/event.js +81 -70
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -55
- package/src/text/bitmaptextdata.js +10 -11
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +49 -55
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +44 -46
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +60 -62
- package/src/video/renderer.js +53 -58
- package/src/video/texture.js +98 -112
- package/src/video/texture_cache.js +26 -10
- package/src/video/video.js +15 -16
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/glshader.js +37 -39
- package/src/video/webgl/webgl_compositor.js +128 -101
- package/src/video/webgl/webgl_renderer.js +126 -106
- package/src/entity/draggable.js +0 -139
- package/src/entity/droptarget.js +0 -109
package/src/level/level.js
CHANGED
|
@@ -49,10 +49,10 @@ function safeLoadLevel(levelId, options, restart) {
|
|
|
49
49
|
/**
|
|
50
50
|
* Load a TMX level
|
|
51
51
|
* @name loadTMXLevel
|
|
52
|
-
* @
|
|
52
|
+
* @memberof level
|
|
53
53
|
* @private
|
|
54
54
|
* @param {string} levelId level id
|
|
55
|
-
* @param {
|
|
55
|
+
* @param {Container} container target container
|
|
56
56
|
* @param {boolean} [flatten=true] if true, flatten all objects into the given container
|
|
57
57
|
* @param {boolean} [setViewportBounds=false] if true, set the viewport bounds to the map size, this should be set to true especially if adding a level to the game world container.
|
|
58
58
|
* @ignore
|
|
@@ -76,7 +76,6 @@ function loadTMXLevel(levelId, container, flatten, setViewportBounds) {
|
|
|
76
76
|
/**
|
|
77
77
|
* a level manager. once ressources loaded, the level manager contains all references of defined levels.
|
|
78
78
|
* @namespace level
|
|
79
|
-
* @memberOf me
|
|
80
79
|
*/
|
|
81
80
|
|
|
82
81
|
var level = {
|
|
@@ -84,7 +83,7 @@ var level = {
|
|
|
84
83
|
/**
|
|
85
84
|
* add a level into the game manager (usually called by the preloader)
|
|
86
85
|
* @name add
|
|
87
|
-
* @
|
|
86
|
+
* @memberof level
|
|
88
87
|
* @public
|
|
89
88
|
* @function
|
|
90
89
|
* @param {string} format level format (only "tmx" supported)
|
|
@@ -123,14 +122,14 @@ var level = {
|
|
|
123
122
|
* load a level into the game manager<br>
|
|
124
123
|
* (will also create all level defined entities, etc..)
|
|
125
124
|
* @name load
|
|
126
|
-
* @
|
|
125
|
+
* @memberof level
|
|
127
126
|
* @public
|
|
128
127
|
* @function
|
|
129
128
|
* @param {string} levelId level id
|
|
130
129
|
* @param {object} [options] additional optional parameters
|
|
131
|
-
* @param {
|
|
132
|
-
* @param {Function} [options.onLoaded=
|
|
133
|
-
* @param {boolean} [options.flatten=
|
|
130
|
+
* @param {Container} [options.container=game.world] container in which to load the specified level
|
|
131
|
+
* @param {Function} [options.onLoaded=ame.onLevelLoaded] callback for when the level is fully loaded
|
|
132
|
+
* @param {boolean} [options.flatten=game.mergeGroup] if true, flatten all objects into the given container
|
|
134
133
|
* @param {boolean} [options.setViewportBounds=true] if true, set the viewport bounds to the map size
|
|
135
134
|
* @returns {boolean} true if the level was successfully loaded
|
|
136
135
|
* @example
|
|
@@ -197,7 +196,7 @@ var level = {
|
|
|
197
196
|
/**
|
|
198
197
|
* return the current level id<br>
|
|
199
198
|
* @name getCurrentLevelId
|
|
200
|
-
* @
|
|
199
|
+
* @memberof level
|
|
201
200
|
* @public
|
|
202
201
|
* @function
|
|
203
202
|
* @returns {string}
|
|
@@ -211,10 +210,10 @@ var level = {
|
|
|
211
210
|
* for a reference to the live instantiated level,
|
|
212
211
|
* rather use the container in which it was loaded (e.g. me.game.world)
|
|
213
212
|
* @name getCurrentLevel
|
|
214
|
-
* @
|
|
213
|
+
* @memberof level
|
|
215
214
|
* @public
|
|
216
215
|
* @function
|
|
217
|
-
* @returns {
|
|
216
|
+
* @returns {TMXTileMap}
|
|
218
217
|
*/
|
|
219
218
|
getCurrentLevel() {
|
|
220
219
|
return levels[this.getCurrentLevelId()];
|
|
@@ -223,13 +222,13 @@ var level = {
|
|
|
223
222
|
/**
|
|
224
223
|
* reload the current level
|
|
225
224
|
* @name reload
|
|
226
|
-
* @
|
|
225
|
+
* @memberof level
|
|
227
226
|
* @public
|
|
228
227
|
* @function
|
|
229
228
|
* @param {object} [options] additional optional parameters
|
|
230
|
-
* @param {
|
|
231
|
-
* @param {Function} [options.onLoaded=
|
|
232
|
-
* @param {boolean} [options.flatten=
|
|
229
|
+
* @param {Container} [options.container=game.world] container in which to load the specified level
|
|
230
|
+
* @param {Function} [options.onLoaded=game.onLevelLoaded] callback for when the level is fully loaded
|
|
231
|
+
* @param {boolean} [options.flatten=game.mergeGroup] if true, flatten all objects into the given container
|
|
233
232
|
* @returns {object} the current level
|
|
234
233
|
*/
|
|
235
234
|
reload(options) {
|
|
@@ -241,13 +240,13 @@ var level = {
|
|
|
241
240
|
/**
|
|
242
241
|
* load the next level
|
|
243
242
|
* @name next
|
|
244
|
-
* @
|
|
243
|
+
* @memberof level
|
|
245
244
|
* @public
|
|
246
245
|
* @function
|
|
247
246
|
* @param {object} [options] additional optional parameters
|
|
248
|
-
* @param {
|
|
249
|
-
* @param {Function} [options.onLoaded=
|
|
250
|
-
* @param {boolean} [options.flatten=
|
|
247
|
+
* @param {Container} [options.container=game.world] container in which to load the specified level
|
|
248
|
+
* @param {Function} [options.onLoaded=game.onLevelLoaded] callback for when the level is fully loaded
|
|
249
|
+
* @param {boolean} [options.flatten=game.mergeGroup] if true, flatten all objects into the given container
|
|
251
250
|
* @returns {boolean} true if the next level was successfully loaded
|
|
252
251
|
*/
|
|
253
252
|
next(options) {
|
|
@@ -263,13 +262,13 @@ var level = {
|
|
|
263
262
|
/**
|
|
264
263
|
* load the previous level<br>
|
|
265
264
|
* @name previous
|
|
266
|
-
* @
|
|
265
|
+
* @memberof level
|
|
267
266
|
* @public
|
|
268
267
|
* @function
|
|
269
268
|
* @param {object} [options] additional optional parameters
|
|
270
|
-
* @param {
|
|
271
|
-
* @param {Function} [options.onLoaded=
|
|
272
|
-
* @param {boolean} [options.flatten=
|
|
269
|
+
* @param {Container} [options.container=game.world] container in which to load the specified level
|
|
270
|
+
* @param {Function} [options.onLoaded=game.onLevelLoaded] callback for when the level is fully loaded
|
|
271
|
+
* @param {boolean} [options.flatten=game.mergeGroup] if true, flatten all objects into the given container
|
|
273
272
|
* @returns {boolean} true if the previous level was successfully loaded
|
|
274
273
|
*/
|
|
275
274
|
previous(options) {
|
|
@@ -285,7 +284,7 @@ var level = {
|
|
|
285
284
|
/**
|
|
286
285
|
* return the amount of level preloaded
|
|
287
286
|
* @name levelCount
|
|
288
|
-
* @
|
|
287
|
+
* @memberof level
|
|
289
288
|
* @public
|
|
290
289
|
* @function
|
|
291
290
|
* @returns {number} the amount of level preloaded
|
|
@@ -7,8 +7,6 @@ import { clamp } from "./../../math/math.js";
|
|
|
7
7
|
* @classdesc
|
|
8
8
|
* object group definition as defined in Tiled.
|
|
9
9
|
* (group definition is translated into the virtual `me.game.world` using `me.Container`)
|
|
10
|
-
* @class TMXGroup
|
|
11
|
-
* @constructor
|
|
12
10
|
* @ignore
|
|
13
11
|
*/
|
|
14
12
|
export default class TMXGroup {
|
|
@@ -20,7 +18,7 @@ export default class TMXGroup {
|
|
|
20
18
|
* @public
|
|
21
19
|
* @type {string}
|
|
22
20
|
* @name name
|
|
23
|
-
* @
|
|
21
|
+
* @memberof TMXGroup
|
|
24
22
|
*/
|
|
25
23
|
this.name = data.name;
|
|
26
24
|
|
|
@@ -29,7 +27,7 @@ export default class TMXGroup {
|
|
|
29
27
|
* @public
|
|
30
28
|
* @type {number}
|
|
31
29
|
* @name width
|
|
32
|
-
* @
|
|
30
|
+
* @memberof TMXGroup
|
|
33
31
|
*/
|
|
34
32
|
this.width = data.width || 0;
|
|
35
33
|
|
|
@@ -38,7 +36,7 @@ export default class TMXGroup {
|
|
|
38
36
|
* @public
|
|
39
37
|
* @type {number}
|
|
40
38
|
* @name height
|
|
41
|
-
* @
|
|
39
|
+
* @memberof TMXGroup
|
|
42
40
|
*/
|
|
43
41
|
this.height = data.height || 0;
|
|
44
42
|
|
|
@@ -47,7 +45,7 @@ export default class TMXGroup {
|
|
|
47
45
|
* @public
|
|
48
46
|
* @type {string}
|
|
49
47
|
* @name tintcolor
|
|
50
|
-
* @
|
|
48
|
+
* @memberof TMXGroup
|
|
51
49
|
*/
|
|
52
50
|
this.tintcolor = data.tintcolor;
|
|
53
51
|
|
|
@@ -56,17 +54,17 @@ export default class TMXGroup {
|
|
|
56
54
|
* @public
|
|
57
55
|
* @type {number}
|
|
58
56
|
* @name z
|
|
59
|
-
* @
|
|
57
|
+
* @memberof TMXGroup
|
|
60
58
|
*/
|
|
61
59
|
this.z = z;
|
|
62
60
|
|
|
63
61
|
/**
|
|
64
62
|
* group objects list definition
|
|
65
|
-
* @see
|
|
63
|
+
* @see TMXObject
|
|
66
64
|
* @public
|
|
67
65
|
* @type {object[]}
|
|
68
66
|
* @name name
|
|
69
|
-
* @
|
|
67
|
+
* @memberof TMXGroup
|
|
70
68
|
*/
|
|
71
69
|
this.objects = [];
|
|
72
70
|
|
|
@@ -63,23 +63,20 @@ function preRenderLayer(layer, renderer) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
+
* @classdesc
|
|
66
67
|
* a TMX Tile Layer Object
|
|
67
68
|
* Tiled QT 0.7.x format
|
|
68
|
-
* @
|
|
69
|
-
* @extends me.Renderable
|
|
70
|
-
* @memberOf me
|
|
71
|
-
* @constructor
|
|
72
|
-
* @param {object} map layer data in JSON format ({@link http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#layer})
|
|
73
|
-
* @param {object} data layer data in JSON format ({@link http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#layer})
|
|
74
|
-
* @param {number} tilewidth width of each tile in pixels
|
|
75
|
-
* @param {number} tileheight height of each tile in pixels
|
|
76
|
-
* @param {string} orientation "isometric" or "orthogonal"
|
|
77
|
-
* @param {me.TMXTilesetGroup} tilesets tileset as defined in Tiled
|
|
78
|
-
* @param {number} z z-index position
|
|
69
|
+
* @augments Renderable
|
|
79
70
|
*/
|
|
80
71
|
class TMXLayer extends Renderable {
|
|
81
72
|
/**
|
|
82
|
-
* @
|
|
73
|
+
* @param {object} map layer data in JSON format ({@link http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#layer})
|
|
74
|
+
* @param {object} data layer data in JSON format ({@link http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#layer})
|
|
75
|
+
* @param {number} tilewidth width of each tile in pixels
|
|
76
|
+
* @param {number} tileheight height of each tile in pixels
|
|
77
|
+
* @param {string} orientation "isometric" or "orthogonal"
|
|
78
|
+
* @param {TMXTilesetGroup} tilesets tileset as defined in Tiled
|
|
79
|
+
* @param {number} z z-index position
|
|
83
80
|
*/
|
|
84
81
|
constructor(map, data, tilewidth, tileheight, orientation, tilesets, z) {
|
|
85
82
|
// super constructor
|
|
@@ -95,8 +92,8 @@ class TMXLayer extends Renderable {
|
|
|
95
92
|
/**
|
|
96
93
|
* The Layer corresponding Tilesets
|
|
97
94
|
* @public
|
|
98
|
-
* @type {
|
|
99
|
-
* @name
|
|
95
|
+
* @type {TMXTilesetGroup}
|
|
96
|
+
* @name TMXLayer#tilesets
|
|
100
97
|
*/
|
|
101
98
|
this.tilesets = tilesets;
|
|
102
99
|
|
|
@@ -118,8 +115,8 @@ class TMXLayer extends Renderable {
|
|
|
118
115
|
/**
|
|
119
116
|
* All animated tilesets in this layer
|
|
120
117
|
* @ignore
|
|
121
|
-
* @type {
|
|
122
|
-
* @name
|
|
118
|
+
* @type {TMXTileset[]}
|
|
119
|
+
* @name TMXLayer#animatedTilesets
|
|
123
120
|
*/
|
|
124
121
|
this.animatedTilesets = [];
|
|
125
122
|
|
|
@@ -127,7 +124,7 @@ class TMXLayer extends Renderable {
|
|
|
127
124
|
* Layer contains tileset animations
|
|
128
125
|
* @public
|
|
129
126
|
* @type {boolean}
|
|
130
|
-
* @name
|
|
127
|
+
* @name TMXLayer#isAnimated
|
|
131
128
|
*/
|
|
132
129
|
this.isAnimated = false;
|
|
133
130
|
|
|
@@ -137,7 +134,7 @@ class TMXLayer extends Renderable {
|
|
|
137
134
|
* @public
|
|
138
135
|
* @type {string}
|
|
139
136
|
* @default "right-down"
|
|
140
|
-
* @name
|
|
137
|
+
* @name TMXLayer#renderorder
|
|
141
138
|
*/
|
|
142
139
|
this.renderorder = data.renderorder || "right-down";
|
|
143
140
|
|
|
@@ -243,10 +240,10 @@ class TMXLayer extends Renderable {
|
|
|
243
240
|
/**
|
|
244
241
|
* Set the TMX renderer for this layer object
|
|
245
242
|
* @name setRenderer
|
|
246
|
-
* @
|
|
243
|
+
* @memberof TMXLayer
|
|
247
244
|
* @public
|
|
248
245
|
* @function
|
|
249
|
-
* @param {
|
|
246
|
+
* @param {TMXRenderer} renderer
|
|
250
247
|
* @example
|
|
251
248
|
* // use the parent map default renderer
|
|
252
249
|
* var layer = new me.TMXLayer(...);
|
|
@@ -259,10 +256,10 @@ class TMXLayer extends Renderable {
|
|
|
259
256
|
/**
|
|
260
257
|
* Return the layer current renderer object
|
|
261
258
|
* @name getRenderer
|
|
262
|
-
* @
|
|
259
|
+
* @memberof TMXLayer
|
|
263
260
|
* @public
|
|
264
261
|
* @function
|
|
265
|
-
* @returns {
|
|
262
|
+
* @returns {TMXRenderer} renderer
|
|
266
263
|
*/
|
|
267
264
|
getRenderer() {
|
|
268
265
|
return this.renderer;
|
|
@@ -272,7 +269,7 @@ class TMXLayer extends Renderable {
|
|
|
272
269
|
/**
|
|
273
270
|
* Return the TileId of the Tile at the specified position
|
|
274
271
|
* @name getTileId
|
|
275
|
-
* @
|
|
272
|
+
* @memberof TMXLayer
|
|
276
273
|
* @public
|
|
277
274
|
* @function
|
|
278
275
|
* @param {number} x X coordinate (in world/pixels coordinates)
|
|
@@ -287,12 +284,12 @@ class TMXLayer extends Renderable {
|
|
|
287
284
|
/**
|
|
288
285
|
* Return the Tile object at the specified position
|
|
289
286
|
* @name getTile
|
|
290
|
-
* @
|
|
287
|
+
* @memberof TMXLayer
|
|
291
288
|
* @public
|
|
292
289
|
* @function
|
|
293
290
|
* @param {number} x X coordinate (in world/pixels coordinates)
|
|
294
291
|
* @param {number} y Y coordinate (in world/pixels coordinates)
|
|
295
|
-
* @returns {
|
|
292
|
+
* @returns {Tile} corresponding tile or null if there is no defined tile at the coordinate or if outside of the layer bounds
|
|
296
293
|
* @example
|
|
297
294
|
* // get the TMX Map Layer called "Front layer"
|
|
298
295
|
* var layer = me.game.world.getChildByName("Front Layer")[0];
|
|
@@ -313,13 +310,13 @@ class TMXLayer extends Renderable {
|
|
|
313
310
|
/**
|
|
314
311
|
* assign the given Tile object to the specified position
|
|
315
312
|
* @name getTile
|
|
316
|
-
* @
|
|
313
|
+
* @memberof TMXLayer
|
|
317
314
|
* @public
|
|
318
315
|
* @function
|
|
319
|
-
* @param {
|
|
316
|
+
* @param {Tile} tile the tile object to be assigned
|
|
320
317
|
* @param {number} x x coordinate (in world/pixels coordinates)
|
|
321
318
|
* @param {number} y y coordinate (in world/pixels coordinates)
|
|
322
|
-
* @returns {
|
|
319
|
+
* @returns {Tile} the tile object
|
|
323
320
|
*/
|
|
324
321
|
setTile(tile, x, y) {
|
|
325
322
|
this.layerData[x][y] = tile;
|
|
@@ -329,13 +326,13 @@ class TMXLayer extends Renderable {
|
|
|
329
326
|
/**
|
|
330
327
|
* return a new the Tile object corresponding to the given tile id
|
|
331
328
|
* @name setTile
|
|
332
|
-
* @
|
|
329
|
+
* @memberof TMXLayer
|
|
333
330
|
* @public
|
|
334
331
|
* @function
|
|
335
332
|
* @param {number} tileId tileId
|
|
336
333
|
* @param {number} x X coordinate (in world/pixels coordinates)
|
|
337
334
|
* @param {number} y Y coordinate (in world/pixels coordinates)
|
|
338
|
-
* @returns {
|
|
335
|
+
* @returns {Tile} the tile object
|
|
339
336
|
*/
|
|
340
337
|
getTileById(tileId, x, y) {
|
|
341
338
|
if (!this.tileset.contains(tileId)) {
|
|
@@ -348,13 +345,13 @@ class TMXLayer extends Renderable {
|
|
|
348
345
|
/**
|
|
349
346
|
* Return the Tile object at the specified tile coordinates
|
|
350
347
|
* @name cellAt
|
|
351
|
-
* @
|
|
348
|
+
* @memberof TMXLayer
|
|
352
349
|
* @public
|
|
353
350
|
* @function
|
|
354
351
|
* @param {number} x x position of the tile (in Tile unit)
|
|
355
352
|
* @param {number} y x position of the tile (in Tile unit)
|
|
356
353
|
* @param {number} [boundsCheck=true] check first if within the layer bounds
|
|
357
|
-
* @returns {
|
|
354
|
+
* @returns {Tile} corresponding tile or null if there is no defined tile at the position or if outside of the layer bounds
|
|
358
355
|
* @example
|
|
359
356
|
* // return the first tile at offset 0, 0
|
|
360
357
|
* var tile = layer.cellAt(0, 0);
|
|
@@ -375,7 +372,7 @@ class TMXLayer extends Renderable {
|
|
|
375
372
|
/**
|
|
376
373
|
* clear the tile at the specified position
|
|
377
374
|
* @name clearTile
|
|
378
|
-
* @
|
|
375
|
+
* @memberof TMXLayer
|
|
379
376
|
* @public
|
|
380
377
|
* @function
|
|
381
378
|
* @param {number} x X coordinate (in map coordinates: row/column)
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import Vector2d from "./../../math/vector2.js";
|
|
2
2
|
import { applyTMXProperties } from "./TMXUtils.js";
|
|
3
3
|
import Tile from "./TMXTile.js";
|
|
4
|
-
import Ellipse from "./../../
|
|
5
|
-
import Polygon from "./../../
|
|
6
|
-
import Line from "./../../
|
|
4
|
+
import Ellipse from "./../../geometries/ellipse.js";
|
|
5
|
+
import Polygon from "./../../geometries/poly.js";
|
|
6
|
+
import Line from "./../../geometries/line.js";
|
|
7
7
|
import { degToRad } from "./../../math/math.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
+
* @classdesc
|
|
10
11
|
* a TMX Object defintion, as defined in Tiled
|
|
11
12
|
* (Object definition is translated into the virtual `me.game.world` using `me.Renderable`)
|
|
12
|
-
* @class TMXObject
|
|
13
|
-
* @constructor
|
|
14
13
|
* @ignore
|
|
15
14
|
*/
|
|
16
15
|
export default class TMXObject {
|
|
@@ -22,7 +21,7 @@ export default class TMXObject {
|
|
|
22
21
|
* @public
|
|
23
22
|
* @type {object[]}
|
|
24
23
|
* @name points
|
|
25
|
-
* @
|
|
24
|
+
* @memberof TMXObject
|
|
26
25
|
*/
|
|
27
26
|
this.points = undefined;
|
|
28
27
|
|
|
@@ -31,7 +30,7 @@ export default class TMXObject {
|
|
|
31
30
|
* @public
|
|
32
31
|
* @type {string}
|
|
33
32
|
* @name name
|
|
34
|
-
* @
|
|
33
|
+
* @memberof TMXObject
|
|
35
34
|
*/
|
|
36
35
|
this.name = settings.name;
|
|
37
36
|
|
|
@@ -40,7 +39,7 @@ export default class TMXObject {
|
|
|
40
39
|
* @public
|
|
41
40
|
* @type {number}
|
|
42
41
|
* @name x
|
|
43
|
-
* @
|
|
42
|
+
* @memberof TMXObject
|
|
44
43
|
*/
|
|
45
44
|
this.x = +settings.x;
|
|
46
45
|
|
|
@@ -49,7 +48,7 @@ export default class TMXObject {
|
|
|
49
48
|
* @public
|
|
50
49
|
* @type {number}
|
|
51
50
|
* @name y
|
|
52
|
-
* @
|
|
51
|
+
* @memberof TMXObject
|
|
53
52
|
*/
|
|
54
53
|
this.y = +settings.y;
|
|
55
54
|
|
|
@@ -58,7 +57,7 @@ export default class TMXObject {
|
|
|
58
57
|
* @public
|
|
59
58
|
* @type {number}
|
|
60
59
|
* @name z
|
|
61
|
-
* @
|
|
60
|
+
* @memberof TMXObject
|
|
62
61
|
*/
|
|
63
62
|
this.z = +z;
|
|
64
63
|
|
|
@@ -67,7 +66,7 @@ export default class TMXObject {
|
|
|
67
66
|
* @public
|
|
68
67
|
* @type {number}
|
|
69
68
|
* @name width
|
|
70
|
-
* @
|
|
69
|
+
* @memberof TMXObject
|
|
71
70
|
*/
|
|
72
71
|
this.width = +settings.width || 0;
|
|
73
72
|
|
|
@@ -76,7 +75,7 @@ export default class TMXObject {
|
|
|
76
75
|
* @public
|
|
77
76
|
* @type {number}
|
|
78
77
|
* @name height
|
|
79
|
-
* @
|
|
78
|
+
* @memberof TMXObject
|
|
80
79
|
*/
|
|
81
80
|
this.height = +settings.height || 0;
|
|
82
81
|
|
|
@@ -86,7 +85,7 @@ export default class TMXObject {
|
|
|
86
85
|
* @public
|
|
87
86
|
* @type {number}
|
|
88
87
|
* @name gid
|
|
89
|
-
* @
|
|
88
|
+
* @memberof TMXObject
|
|
90
89
|
*/
|
|
91
90
|
this.gid = +settings.gid || null;
|
|
92
91
|
|
|
@@ -95,7 +94,7 @@ export default class TMXObject {
|
|
|
95
94
|
* @public
|
|
96
95
|
* @type {string}
|
|
97
96
|
* @name tintcolor
|
|
98
|
-
* @
|
|
97
|
+
* @memberof TMXObject
|
|
99
98
|
*/
|
|
100
99
|
this.tintcolor = settings.tintcolor;
|
|
101
100
|
|
|
@@ -104,7 +103,7 @@ export default class TMXObject {
|
|
|
104
103
|
* @public
|
|
105
104
|
* @type {string}
|
|
106
105
|
* @name type
|
|
107
|
-
* @
|
|
106
|
+
* @memberof TMXObject
|
|
108
107
|
*/
|
|
109
108
|
this.type = settings.type;
|
|
110
109
|
|
|
@@ -114,7 +113,7 @@ export default class TMXObject {
|
|
|
114
113
|
* @type {object}
|
|
115
114
|
* @see http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#text
|
|
116
115
|
* @name type
|
|
117
|
-
* @
|
|
116
|
+
* @memberof TMXObject
|
|
118
117
|
*/
|
|
119
118
|
this.type = settings.type;
|
|
120
119
|
|
|
@@ -123,7 +122,7 @@ export default class TMXObject {
|
|
|
123
122
|
* @public
|
|
124
123
|
* @type {number}
|
|
125
124
|
* @name rotation
|
|
126
|
-
* @
|
|
125
|
+
* @memberof TMXObject
|
|
127
126
|
*/
|
|
128
127
|
this.rotation = degToRad(+settings.rotation || 0);
|
|
129
128
|
|
|
@@ -132,7 +131,7 @@ export default class TMXObject {
|
|
|
132
131
|
* @public
|
|
133
132
|
* @type {number}
|
|
134
133
|
* @name id
|
|
135
|
-
* @
|
|
134
|
+
* @memberof TMXObject
|
|
136
135
|
*/
|
|
137
136
|
this.id = +settings.id || undefined;
|
|
138
137
|
|
|
@@ -141,7 +140,7 @@ export default class TMXObject {
|
|
|
141
140
|
* @public
|
|
142
141
|
* @type {string}
|
|
143
142
|
* @name orientation
|
|
144
|
-
* @
|
|
143
|
+
* @memberof TMXObject
|
|
145
144
|
*/
|
|
146
145
|
this.orientation = map.orientation;
|
|
147
146
|
|
|
@@ -150,7 +149,7 @@ export default class TMXObject {
|
|
|
150
149
|
* @public
|
|
151
150
|
* @type {object[]}
|
|
152
151
|
* @name shapes
|
|
153
|
-
* @
|
|
152
|
+
* @memberof TMXObject
|
|
154
153
|
*/
|
|
155
154
|
this.shapes = undefined;
|
|
156
155
|
|
|
@@ -159,7 +158,7 @@ export default class TMXObject {
|
|
|
159
158
|
* @public
|
|
160
159
|
* @type {boolean}
|
|
161
160
|
* @name isEllipse
|
|
162
|
-
* @
|
|
161
|
+
* @memberof TMXObject
|
|
163
162
|
*/
|
|
164
163
|
this.isEllipse = false;
|
|
165
164
|
|
|
@@ -168,7 +167,7 @@ export default class TMXObject {
|
|
|
168
167
|
* @public
|
|
169
168
|
* @type {boolean}
|
|
170
169
|
* @name isPolygon
|
|
171
|
-
* @
|
|
170
|
+
* @memberof TMXObject
|
|
172
171
|
*/
|
|
173
172
|
this.isPolygon = false;
|
|
174
173
|
|
|
@@ -177,7 +176,7 @@ export default class TMXObject {
|
|
|
177
176
|
* @public
|
|
178
177
|
* @type {boolean}
|
|
179
178
|
* @name isPolyLine
|
|
180
|
-
* @
|
|
179
|
+
* @memberof TMXObject
|
|
181
180
|
*/
|
|
182
181
|
this.isPolyLine = false;
|
|
183
182
|
|
|
@@ -249,10 +248,10 @@ export default class TMXObject {
|
|
|
249
248
|
/**
|
|
250
249
|
* parses the TMX shape definition and returns a corresponding array of me.Shape object
|
|
251
250
|
* @name parseTMXShapes
|
|
252
|
-
* @
|
|
251
|
+
* @memberof TMXObject
|
|
253
252
|
* @private
|
|
254
253
|
* @function
|
|
255
|
-
* @returns {
|
|
254
|
+
* @returns {Polygon[]|Line[]|Ellipse[]} an array of shape objects
|
|
256
255
|
*/
|
|
257
256
|
parseTMXShapes() {
|
|
258
257
|
var i = 0;
|
|
@@ -267,39 +266,46 @@ export default class TMXObject {
|
|
|
267
266
|
this.width,
|
|
268
267
|
this.height
|
|
269
268
|
)).rotate(this.rotation));
|
|
270
|
-
}
|
|
269
|
+
} else {
|
|
271
270
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
// add a polygon
|
|
272
|
+
if (this.isPolygon === true) {
|
|
273
|
+
var _polygon = new Polygon(0, 0, this.points);
|
|
274
|
+
// make sure it's a convex polygon
|
|
275
|
+
if (_polygon.isConvex() === false ) {
|
|
276
|
+
throw new Error("collision polygones in Tiled should be defined as Convex");
|
|
277
|
+
}
|
|
278
|
+
shapes.push(_polygon.rotate(this.rotation));
|
|
279
|
+
}
|
|
276
280
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
281
|
+
// add a polyline
|
|
282
|
+
else if (this.isPolyLine === true) {
|
|
283
|
+
var p = this.points;
|
|
284
|
+
var p1, p2;
|
|
285
|
+
var segments = p.length - 1;
|
|
286
|
+
for (i = 0; i < segments; i++) {
|
|
287
|
+
// clone the value before, as [i + 1]
|
|
288
|
+
// is reused later by the next segment
|
|
289
|
+
p1 = new Vector2d(p[i].x, p[i].y);
|
|
290
|
+
p2 = new Vector2d(p[i + 1].x, p[i + 1].y);
|
|
291
|
+
if (this.rotation !== 0) {
|
|
292
|
+
p1 = p1.rotate(this.rotation);
|
|
293
|
+
p2 = p2.rotate(this.rotation);
|
|
294
|
+
}
|
|
295
|
+
shapes.push(new Line(0, 0, [ p1, p2 ]));
|
|
290
296
|
}
|
|
291
|
-
shapes.push(new Line(0, 0, [ p1, p2 ]));
|
|
292
297
|
}
|
|
293
|
-
}
|
|
294
298
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
299
|
+
// it's a rectangle, returns a polygon object anyway
|
|
300
|
+
else {
|
|
301
|
+
shapes.push((new Polygon(
|
|
302
|
+
0, 0, [
|
|
303
|
+
new Vector2d(), new Vector2d(this.width, 0),
|
|
304
|
+
new Vector2d(this.width, this.height), new Vector2d(0, this.height)
|
|
305
|
+
]
|
|
306
|
+
)).rotate(this.rotation));
|
|
307
|
+
}
|
|
308
|
+
|
|
303
309
|
}
|
|
304
310
|
|
|
305
311
|
// Apply isometric projection
|