From 123c8f8127ee6dc1c9a06d68411eb74748e05955 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 23 Jan 2018 02:12:33 +0000 Subject: [PATCH 01/11] Calls to the Scene Manager that happen before the Scene is running are now queued Thanks to gdomaradzki for bringing this one to my attention! --- src/scene/SceneManager.js | 39 ++++++++++++++++++++++----------------- src/scene/ScenePlugin.js | 31 +++++++++++++++++++++++++++---- src/scene/const.js | 11 ++++++----- 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/scene/SceneManager.js b/src/scene/SceneManager.js index c582a7e9c..02a21a568 100644 --- a/src/scene/SceneManager.js +++ b/src/scene/SceneManager.js @@ -90,25 +90,21 @@ var SceneManager = new Class({ this.start(entry); } + + // Clear the pending lists + this._start.length = 0; + this._pending.length = 0; + + return; } for (i = 0; i < queueLength; i++) { entry = this._queue[i]; - if (entry.op === 'swapPosition') - { - this.swapPosition(entry.keyA, entry.keyB); - } - else - { - this[entry.op](entry.key); - } + this[entry.op](entry.keyA, entry.keyB); } - - // Clear the pending lists - this._start.length = 0; - this._pending.length = 0; + this._queue.length = 0; }, @@ -342,9 +338,11 @@ var SceneManager = new Class({ { if (scene.create) { + scene.sys.settings.status = CONST.CREATING; + scene.create.call(scene, scene.sys.settings.data); } - + scene.sys.settings.status = CONST.RUNNING; }, @@ -902,7 +900,7 @@ var SceneManager = new Class({ { if (this._processing) { - this._queue.push( { op: 'bringToTop', key: key }); + this._queue.push( { op: 'bringToTop', keyA: key, keyB: null }); } else { @@ -934,7 +932,7 @@ var SceneManager = new Class({ { if (this._processing) { - this._queue.push( { op: 'sendToBack', key: key }); + this._queue.push( { op: 'sendToBack', keyA: key, keyB: null }); } else { @@ -966,7 +964,7 @@ var SceneManager = new Class({ { if (this._processing) { - this._queue.push( { op: 'moveDown', key: key }); + this._queue.push( { op: 'moveDown', keyA: key, keyB: null }); } else { @@ -1000,7 +998,7 @@ var SceneManager = new Class({ { if (this._processing) { - this._queue.push( { op: 'moveUp', key: key }); + this._queue.push( { op: 'moveUp', keyA: key, keyB: null }); } else { @@ -1020,6 +1018,13 @@ var SceneManager = new Class({ return this; }, + queueOp: function (op, keyA, keyB) + { + this._queue.push( { op: op, keyA: keyA, keyB: keyB }); + + return this; + }, + /** * [description] * diff --git a/src/scene/ScenePlugin.js b/src/scene/ScenePlugin.js index cf84155ef..ed1d61487 100644 --- a/src/scene/ScenePlugin.js +++ b/src/scene/ScenePlugin.js @@ -1,4 +1,5 @@ var Class = require('../utils/Class'); +var CONST = require('./const'); var PluginManager = require('../plugins/PluginManager'); // A proxy class to the Global Scene Manager @@ -44,8 +45,16 @@ var ScenePlugin = new Class({ if (key !== this.key) { - this.manager.stop(this.key); - this.manager.start(key); + if (this.settings.status !== CONST.RUNNING) + { + this.manager.queueOp('stop', this.key); + this.manager.queueOp('start', key); + } + else + { + this.manager.stop(this.key); + this.manager.start(key); + } } return this; @@ -64,7 +73,14 @@ var ScenePlugin = new Class({ { if (key && key !== this.key) { - this.manager.start(key); + if (this.settings.status !== CONST.RUNNING) + { + this.manager.queueOp('start', key); + } + else + { + this.manager.start(key); + } } return this; @@ -115,7 +131,14 @@ var ScenePlugin = new Class({ { if (key !== this.key) { - this.manager.switch(this.key, key); + if (this.settings.status !== CONST.RUNNING) + { + this.manager.queueOp('switch', this.key, key); + } + else + { + this.manager.switch(this.key, key); + } } return this; diff --git a/src/scene/const.js b/src/scene/const.js index 7a7c4a746..6252383ed 100644 --- a/src/scene/const.js +++ b/src/scene/const.js @@ -5,10 +5,11 @@ module.exports = { INIT: 1, START: 2, LOADING: 3, - RUNNING: 4, - PAUSED: 5, - SLEEPING: 6, - SHUTDOWN: 7, - DESTROYED: 8 + CREATING: 4, + RUNNING: 5, + PAUSED: 6, + SLEEPING: 7, + SHUTDOWN: 8, + DESTROYED: 9 }; From 2bf0381821f907a592e5760506ef7a88737342f1 Mon Sep 17 00:00:00 2001 From: Artem Date: Tue, 23 Jan 2018 14:37:25 +0100 Subject: [PATCH 02/11] clock timescale applied to timer --- src/time/Clock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time/Clock.js b/src/time/Clock.js index 17bf57857..ae70bbe50 100644 --- a/src/time/Clock.js +++ b/src/time/Clock.js @@ -120,7 +120,7 @@ var Clock = new Class({ return; } - delta * this.timeScale; + delta *= this.timeScale; for (var i = 0; i < this._active.length; i++) { From ab290157425b4905a333c5b6124e4042242d7915 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Mon, 22 Jan 2018 20:20:58 -0600 Subject: [PATCH 03/11] Convenience tile getters for looking up tileset & tilemap layer --- src/gameobjects/tilemap/Tile.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/gameobjects/tilemap/Tile.js b/src/gameobjects/tilemap/Tile.js index 4078e2f15..d321bf108 100644 --- a/src/gameobjects/tilemap/Tile.js +++ b/src/gameobjects/tilemap/Tile.js @@ -510,8 +510,35 @@ var Tile = new Class({ { return this.pixelY + this.height / 2; } - } + }, + /** + * The tileset that contains this Tile. This will only return null if accessed from a LayerData + * instance before the tile is placed within a StaticTilemapLayer or DynamicTilemapLayer. + * @property {Tileset|null} tileset + * @readonly + */ + tileset: { + get: function () + { + var tilemapLayer = this.tilemapLayer; + return tilemapLayer ? tilemapLayer.tileset : null; + } + }, + + /** + * The tilemap layer that contains this Tile. This will only return null if accessed from a + * LayerData instance before the tile is placed within a StaticTilemapLayer or + * DynamicTilemapLayer. + * @property {StaticTilemapLayer|DynamicTilemapLayer|null} tilemapLayer + * @readonly + */ + tilemapLayer: { + get: function () + { + return this.layer.tilemapLayer; + } + } }); module.exports = Tile; From c7a471e29a06141905d6a48bfae04f2c44e67fee Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Tue, 23 Jan 2018 07:52:53 -0600 Subject: [PATCH 04/11] Convenience for getting Tileset collision group from Tile --- src/gameobjects/tilemap/Tile.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/gameobjects/tilemap/Tile.js b/src/gameobjects/tilemap/Tile.js index d321bf108..0ee784922 100644 --- a/src/gameobjects/tilemap/Tile.js +++ b/src/gameobjects/tilemap/Tile.js @@ -229,6 +229,17 @@ var Tile = new Class({ return this; }, + /** + * The collision group for this Tile, defined within the Tileset. This returns a reference to + * the collision group stored within the Tileset, so any modification of the returned object + * will impact all tiles that have the same index as this tile. + * @returns {object|null} tileset + */ + getCollisionGroup: function () + { + return this.tileset ? this.tileset.getTileCollisionGroup(this.index) : null; + }, + /** * Clean up memory. */ From b8b0f42153464e0f4a383af3673d4b81a456cfba Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Tue, 23 Jan 2018 07:54:03 -0600 Subject: [PATCH 05/11] getTileProperty -> getTileProperties A tile can have multiple properties, so it makes more sense as a plural method name --- src/gameobjects/tilemap/Tileset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gameobjects/tilemap/Tileset.js b/src/gameobjects/tilemap/Tileset.js index ce5de6dcb..07bd32c0c 100644 --- a/src/gameobjects/tilemap/Tileset.js +++ b/src/gameobjects/tilemap/Tileset.js @@ -128,7 +128,7 @@ var Tileset = new Class({ * @param {integer} tileIndex - The unique id of the tile across all tilesets in the map. * @returns {object|undefined|null} */ - getTileProperty: function (tileIndex) + getTileProperties: function (tileIndex) { if (!this.containsTileIndex(tileIndex)) { return null; } return this.tileProperties[tileIndex - this.firstgid]; From 629ead9a37af34ba546604020f329fba1b413b9b Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Tue, 23 Jan 2018 07:55:43 -0600 Subject: [PATCH 06/11] Making Tileset comments more specific - better explains Tiled structure --- src/gameobjects/tilemap/Tileset.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gameobjects/tilemap/Tileset.js b/src/gameobjects/tilemap/Tileset.js index 07bd32c0c..5be66c352 100644 --- a/src/gameobjects/tilemap/Tileset.js +++ b/src/gameobjects/tilemap/Tileset.js @@ -72,14 +72,15 @@ var Tileset = new Class({ this.tileSpacing = tileSpacing; /** - * Tileset-specific properties per tile that are typically defined in the Tiled editor. + * Tileset-specific properties per tile that are typically defined in the Tiled editor in the + * Tileset editor. * @property {object} tileProperties */ this.tileProperties = tileProperties; /** - * Tileset-specific data per tile that are typically defined in the Tiled editor. This is - * where collision objects and terrain are stored. + * Tileset-specific data per tile that are typically defined in the Tiled editor, e.g. within + * the Tilset collision editor. This is where collision objects and terrain are stored. * @property {object} tileData */ this.tileData = tileData; @@ -123,7 +124,7 @@ var Tileset = new Class({ /** * Get a tile's properties that are stored in the Tileset. Returns null if tile index is not - * contained in this Tileset. + * contained in this Tileset. This is typically defined in Tiled under the Tileset editor. * * @param {integer} tileIndex - The unique id of the tile across all tilesets in the map. * @returns {object|undefined|null} @@ -135,8 +136,9 @@ var Tileset = new Class({ }, /** - * Get a tile's data that is stored in the Tileset. Returns null if tile index is not - * contained in this Tileset. + * Get a tile's data that is stored in the Tileset. Returns null if tile index is not contained + * in this Tileset. This is typically defined in Tiled and will contain both Tileset collision + * info and terrain mapping. * * @param {integer} tileIndex - The unique id of the tile across all tilesets in the map. * @returns {object|undefined|null} @@ -148,8 +150,8 @@ var Tileset = new Class({ }, /** - * Get a tile's data that is stored in the Tileset. Returns null if tile index is not - * contained in this Tileset. + * Get a tile's collision group that is stored in the Tileset. Returns null if tile index is not + * contained in this Tileset. This is typically defined within Tiled's tileset collision editor. * * @param {integer} tileIndex - The unique id of the tile across all tilesets in the map. * @returns {object|null} From cb3166850e0567aa14bef96bc38996a05befd361 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 23 Jan 2018 14:37:23 +0000 Subject: [PATCH 07/11] Fixed issue with Keyboard events for single key presses. Added new KeyMap. --- src/input/keyboard/KeyboardManager.js | 19 ++++++++++++------- src/input/keyboard/keys/KeyMap.js | 10 ++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 src/input/keyboard/keys/KeyMap.js diff --git a/src/input/keyboard/KeyboardManager.js b/src/input/keyboard/KeyboardManager.js index 91d79c9bf..5f5d1707b 100644 --- a/src/input/keyboard/KeyboardManager.js +++ b/src/input/keyboard/KeyboardManager.js @@ -3,6 +3,7 @@ var EventEmitter = require('eventemitter3'); var Key = require('./keys/Key'); var KeyCodes = require('./keys/KeyCodes'); var KeyCombo = require('./combo/KeyCombo'); +var KeyMap = require('./keys/KeyMap'); var ProcessKeyCombo = require('./combo/ProcessKeyCombo'); var ProcessKeyDown = require('./keys/ProcessKeyDown'); var ProcessKeyUp = require('./keys/ProcessKeyUp'); @@ -215,26 +216,30 @@ var KeyboardManager = new Class({ for (var i = 0; i < len; i++) { var event = queue[i]; + var code = event.keyCode; // Will emit a keyboard or keyup event this.emit(event.type, event); if (event.type === 'keydown') { - this.emit('down_' + event.keyCode, event); - - if (keys[event.keyCode]) + if (KeyMap[code]) { - ProcessKeyDown(keys[event.keyCode], event); + this.emit('keydown_' + KeyMap[code], event); + } + + if (keys[code]) + { + ProcessKeyDown(keys[code], event); } } else { - this.emit('up_' + event.keyCode, event); + this.emit('keyup_' + KeyMap[code], event); - if (keys[event.keyCode]) + if (keys[code]) { - ProcessKeyUp(keys[event.keyCode], event); + ProcessKeyUp(keys[code], event); } } } diff --git a/src/input/keyboard/keys/KeyMap.js b/src/input/keyboard/keys/KeyMap.js new file mode 100644 index 000000000..a01673ca3 --- /dev/null +++ b/src/input/keyboard/keys/KeyMap.js @@ -0,0 +1,10 @@ +var KeyCodes = require('./KeyCodes'); + +var KeyMap = {}; + +for (var key in KeyCodes) +{ + KeyMap[KeyCodes[key]] = key; +} + +module.exports = KeyMap; From e31ea73ad4fdc17c4246e1df6f28f19da2506746 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Tue, 23 Jan 2018 08:38:25 -0600 Subject: [PATCH 08/11] Typo fix: Tilset -> Tileset --- src/gameobjects/tilemap/Tileset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gameobjects/tilemap/Tileset.js b/src/gameobjects/tilemap/Tileset.js index 5be66c352..676941ec1 100644 --- a/src/gameobjects/tilemap/Tileset.js +++ b/src/gameobjects/tilemap/Tileset.js @@ -80,7 +80,7 @@ var Tileset = new Class({ /** * Tileset-specific data per tile that are typically defined in the Tiled editor, e.g. within - * the Tilset collision editor. This is where collision objects and terrain are stored. + * the Tileset collision editor. This is where collision objects and terrain are stored. * @property {object} tileData */ this.tileData = tileData; From 2cabd15684ff3085d19dce944803ad025bc084e1 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Tue, 23 Jan 2018 09:05:37 -0600 Subject: [PATCH 09/11] Added SetCollisionByProperty to Tilemap API --- src/gameobjects/tilemap/Tilemap.js | 13 ++++ .../components/SetCollisionByProperty.js | 59 +++++++++++++++++++ src/gameobjects/tilemap/components/index.js | 1 + .../dynamiclayer/DynamicTilemapLayer.js | 11 ++++ .../tilemap/staticlayer/StaticTilemapLayer.js | 11 ++++ 5 files changed, 95 insertions(+) create mode 100644 src/gameobjects/tilemap/components/SetCollisionByProperty.js diff --git a/src/gameobjects/tilemap/Tilemap.js b/src/gameobjects/tilemap/Tilemap.js index 3eef67da9..329378204 100644 --- a/src/gameobjects/tilemap/Tilemap.js +++ b/src/gameobjects/tilemap/Tilemap.js @@ -1001,6 +1001,19 @@ var Tilemap = new Class({ return this; }, + /** + * See component documentation. If no layer specified, the map's current layer is used. + * + * @return {this|null} Returns this, or null if the layer given was invalid. + */ + setCollisionByProperty: function (properties, collides, recalculateFaces, layer) + { + layer = this.getLayer(layer); + if (layer === null) { return this; } + TilemapComponents.SetCollisionByProperty(properties, collides, recalculateFaces, layer); + return this; + }, + /** * See component documentation. If no layer specified, the map's current layer is used. * diff --git a/src/gameobjects/tilemap/components/SetCollisionByProperty.js b/src/gameobjects/tilemap/components/SetCollisionByProperty.js new file mode 100644 index 000000000..687ab9ca1 --- /dev/null +++ b/src/gameobjects/tilemap/components/SetCollisionByProperty.js @@ -0,0 +1,59 @@ +var SetTileCollision = require('./SetTileCollision'); +var CalculateFacesWithin = require('./CalculateFacesWithin'); +var HasValue = require('../../../utils/object/HasValue'); + +/** + * Sets collision on the tiles within a layer by checking tile properties. If a tile has a property + * that matches the given properties object, its collision flag will be set. The `collides` + * parameter controls if collision will be enabled (true) or disabled (false). Passing in + * `{ collides: true }` would update the collision flag on any tiles with a "collides" property that + * has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can + * also use an array of values, e.g. `{ types: ["stone", "lava", "sand" ] }`. If a tile has a + * "types" property that matches any of those values, its collision flag will be updated. + * + * @param {object} properties - An object with tile properties and corresponding values that should + * be checked. + * @param {boolean} [collides=true] - If true it will enable collision. If false it will clear + * collision. + * @param {boolean} [recalculateFaces=true] - Whether or not to recalculate the tile faces after the + * update. + * @param {LayerData} layer - [description] + */ +var SetCollisionByProperty = function (properties, collides, recalculateFaces, layer) +{ + if (collides === undefined) { collides = true; } + if (recalculateFaces === undefined) { recalculateFaces = true; } + + for (var ty = 0; ty < layer.height; ty++) + { + for (var tx = 0; tx < layer.width; tx++) + { + var tile = layer.data[ty][tx]; + + if (!tile) { continue; } + + for (var property in properties) + { + if (!HasValue(tile.properties, property)) { continue; } + + var values = properties[property]; + if (!Array.isArray(values)) + { + values = [ values ]; + } + + for (var i = 0; i < values.length; i++) + { + if (tile.properties[property] === values[i]) + { + SetTileCollision(tile, collides); + } + } + } + } + } + + if (recalculateFaces) { CalculateFacesWithin(0, 0, layer.width, layer.height, layer); } +}; + +module.exports = SetCollisionByProperty; diff --git a/src/gameobjects/tilemap/components/index.js b/src/gameobjects/tilemap/components/index.js index 07a968e90..cefa132f3 100644 --- a/src/gameobjects/tilemap/components/index.js +++ b/src/gameobjects/tilemap/components/index.js @@ -27,6 +27,7 @@ module.exports = { RenderDebug: require('./RenderDebug'), SetCollision: require('./SetCollision'), SetCollisionBetween: require('./SetCollisionBetween'), + SetCollisionByProperty: require('./SetCollisionByProperty'), SetCollisionByExclusion: require('./SetCollisionByExclusion'), SetTileIndexCallback: require('./SetTileIndexCallback'), SetTileLocationCallback: require('./SetTileLocationCallback'), diff --git a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js index 8e6675748..e96c57b97 100644 --- a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js +++ b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js @@ -383,6 +383,17 @@ var DynamicTilemapLayer = new Class({ return this; }, + /** + * See component documentation. + * + * @return {this} + */ + setCollisionByProperty: function (properties, collides, recalculateFaces) + { + TilemapComponents.SetCollisionByProperty(properties, collides, recalculateFaces, this.layer); + return this; + }, + /** * See component documentation. * diff --git a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js index 7a5397ce8..a2e40f786 100644 --- a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js +++ b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js @@ -448,6 +448,17 @@ var StaticTilemapLayer = new Class({ return this; }, + /** + * See component documentation. + * + * @return {this} + */ + setCollisionByProperty: function (properties, collides, recalculateFaces) + { + TilemapComponents.SetCollisionByProperty(properties, collides, recalculateFaces, this.layer); + return this; + }, + /** * See component documentation. * From 4abf0df11987786b7f2b37ccce872a0ac7e440c4 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Tue, 23 Jan 2018 09:40:59 -0600 Subject: [PATCH 10/11] Added setCollisionFromCollisionGroup for easily setting collision from Tiled collision editor --- src/gameobjects/tilemap/Tilemap.js | 13 ++++++ .../SetCollisionFromCollisionGroup.js | 43 +++++++++++++++++++ src/gameobjects/tilemap/components/index.js | 1 + .../dynamiclayer/DynamicTilemapLayer.js | 11 +++++ .../tilemap/staticlayer/StaticTilemapLayer.js | 11 +++++ 5 files changed, 79 insertions(+) create mode 100644 src/gameobjects/tilemap/components/SetCollisionFromCollisionGroup.js diff --git a/src/gameobjects/tilemap/Tilemap.js b/src/gameobjects/tilemap/Tilemap.js index 329378204..d65221b67 100644 --- a/src/gameobjects/tilemap/Tilemap.js +++ b/src/gameobjects/tilemap/Tilemap.js @@ -1027,6 +1027,19 @@ var Tilemap = new Class({ return this; }, + /** + * See component documentation. If no layer specified, the map's current layer is used. + * + * @return {this|null} Returns this, or null if the layer given was invalid. + */ + setCollisionFromCollisionGroup: function (collides, recalculateFaces, layer) + { + layer = this.getLayer(layer); + if (layer === null) { return this; } + TilemapComponents.SetCollisionFromCollisionGroup(collides, recalculateFaces, layer); + return this; + }, + /** * See component documentation. If no layer specified, the map's current layer is used. * diff --git a/src/gameobjects/tilemap/components/SetCollisionFromCollisionGroup.js b/src/gameobjects/tilemap/components/SetCollisionFromCollisionGroup.js new file mode 100644 index 000000000..0d562ec0b --- /dev/null +++ b/src/gameobjects/tilemap/components/SetCollisionFromCollisionGroup.js @@ -0,0 +1,43 @@ +var SetTileCollision = require('./SetTileCollision'); +var CalculateFacesWithin = require('./CalculateFacesWithin'); + +/** + * Sets collision on the tiles within a layer by checking if the tile has a collision group + * (typically defined in Tiled within the tileset collision editor). If any collision objects are + * found, the tile's colliding information will be set. The `collides` parameter controls if + * collision will be enabled (true) or disabled (false). + * + * @param {boolean} [collides=true] - If true it will enable collision. If false it will clear + * collision. + * @param {boolean} [recalculateFaces=true] - Whether or not to recalculate the tile faces after the + * update. + * @param {LayerData} layer - [description] + */ +var SetCollisionFromCollisionGroup = function (collides, recalculateFaces, layer) +{ + if (collides === undefined) { collides = true; } + if (recalculateFaces === undefined) { recalculateFaces = true; } + + for (var ty = 0; ty < layer.height; ty++) + { + for (var tx = 0; tx < layer.width; tx++) + { + var tile = layer.data[ty][tx]; + + if (!tile) { continue; } + + var collisionGroup = tile.getCollisionGroup(); + + // It's possible in Tiled to have a collision group without any shapes, e.g. create a + // shape and then delete the shape. + if (collisionGroup && collisionGroup.objects && collisionGroup.objects.length > 0) + { + SetTileCollision(tile, collides); + } + } + } + + if (recalculateFaces) { CalculateFacesWithin(0, 0, layer.width, layer.height, layer); } +}; + +module.exports = SetCollisionFromCollisionGroup; diff --git a/src/gameobjects/tilemap/components/index.js b/src/gameobjects/tilemap/components/index.js index cefa132f3..756ad8475 100644 --- a/src/gameobjects/tilemap/components/index.js +++ b/src/gameobjects/tilemap/components/index.js @@ -29,6 +29,7 @@ module.exports = { SetCollisionBetween: require('./SetCollisionBetween'), SetCollisionByProperty: require('./SetCollisionByProperty'), SetCollisionByExclusion: require('./SetCollisionByExclusion'), + SetCollisionFromCollisionGroup: require('./SetCollisionFromCollisionGroup'), SetTileIndexCallback: require('./SetTileIndexCallback'), SetTileLocationCallback: require('./SetTileLocationCallback'), Shuffle: require('./Shuffle'), diff --git a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js index e96c57b97..3d543f13a 100644 --- a/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js +++ b/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js @@ -405,6 +405,17 @@ var DynamicTilemapLayer = new Class({ return this; }, + /** + * See component documentation. + * + * @return {this} + */ + setCollisionFromCollisionGroup: function (collides, recalculateFaces) + { + TilemapComponents.SetCollisionFromCollisionGroup(collides, recalculateFaces, this.layer); + return this; + }, + /** * See component documentation. * diff --git a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js index a2e40f786..2214ea6a2 100644 --- a/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js +++ b/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js @@ -481,6 +481,17 @@ var StaticTilemapLayer = new Class({ return this; }, + /** + * See component documentation. + * + * @return {this} + */ + setCollisionFromCollisionGroup: function (collides, recalculateFaces) + { + TilemapComponents.SetCollisionFromCollisionGroup(collides, recalculateFaces, this.layer); + return this; + }, + /** * See component documentation. * From ebabf97ce3048d7da95b7942ba5c744f12f466b8 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Tue, 23 Jan 2018 09:41:29 -0600 Subject: [PATCH 11/11] Comment clarification --- .../tilemap/components/SetCollisionFromCollisionGroup.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gameobjects/tilemap/components/SetCollisionFromCollisionGroup.js b/src/gameobjects/tilemap/components/SetCollisionFromCollisionGroup.js index 0d562ec0b..0492acbf5 100644 --- a/src/gameobjects/tilemap/components/SetCollisionFromCollisionGroup.js +++ b/src/gameobjects/tilemap/components/SetCollisionFromCollisionGroup.js @@ -2,10 +2,10 @@ var SetTileCollision = require('./SetTileCollision'); var CalculateFacesWithin = require('./CalculateFacesWithin'); /** - * Sets collision on the tiles within a layer by checking if the tile has a collision group - * (typically defined in Tiled within the tileset collision editor). If any collision objects are - * found, the tile's colliding information will be set. The `collides` parameter controls if - * collision will be enabled (true) or disabled (false). + * Sets collision on the tiles within a layer by checking each tile's collision group data + * (typically defined in Tiled within the tileset collision editor). If any objects are found within + * a tile's collision group, the tile's colliding information will be set. The `collides` parameter + * controls if collision will be enabled (true) or disabled (false). * * @param {boolean} [collides=true] - If true it will enable collision. If false it will clear * collision.