mirror of
https://github.com/photonstorm/phaser
synced 2024-12-17 00:23:33 +00:00
Merge branch 'master' into rendering-cleanup
This commit is contained in:
commit
336cc4e3fe
14 changed files with 302 additions and 44 deletions
|
@ -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.
|
||||
*/
|
||||
|
@ -510,8 +521,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;
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -1014,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.
|
||||
*
|
||||
|
|
|
@ -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 Tileset collision editor. This is where collision objects and terrain are stored.
|
||||
* @property {object} tileData
|
||||
*/
|
||||
this.tileData = tileData;
|
||||
|
@ -123,20 +124,21 @@ 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}
|
||||
*/
|
||||
getTileProperty: function (tileIndex)
|
||||
getTileProperties: function (tileIndex)
|
||||
{
|
||||
if (!this.containsTileIndex(tileIndex)) { return null; }
|
||||
return this.tileProperties[tileIndex - this.firstgid];
|
||||
},
|
||||
|
||||
/**
|
||||
* 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}
|
||||
|
|
59
src/gameobjects/tilemap/components/SetCollisionByProperty.js
Normal file
59
src/gameobjects/tilemap/components/SetCollisionByProperty.js
Normal file
|
@ -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;
|
|
@ -0,0 +1,43 @@
|
|||
var SetTileCollision = require('./SetTileCollision');
|
||||
var CalculateFacesWithin = require('./CalculateFacesWithin');
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @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;
|
|
@ -27,7 +27,9 @@ module.exports = {
|
|||
RenderDebug: require('./RenderDebug'),
|
||||
SetCollision: require('./SetCollision'),
|
||||
SetCollisionBetween: require('./SetCollisionBetween'),
|
||||
SetCollisionByProperty: require('./SetCollisionByProperty'),
|
||||
SetCollisionByExclusion: require('./SetCollisionByExclusion'),
|
||||
SetCollisionFromCollisionGroup: require('./SetCollisionFromCollisionGroup'),
|
||||
SetTileIndexCallback: require('./SetTileIndexCallback'),
|
||||
SetTileLocationCallback: require('./SetTileLocationCallback'),
|
||||
Shuffle: require('./Shuffle'),
|
||||
|
|
|
@ -382,6 +382,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.
|
||||
*
|
||||
|
@ -393,6 +404,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.
|
||||
*
|
||||
|
|
|
@ -447,6 +447,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.
|
||||
*
|
||||
|
@ -469,6 +480,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.
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
src/input/keyboard/keys/KeyMap.js
Normal file
10
src/input/keyboard/keys/KeyMap.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
var KeyCodes = require('./KeyCodes');
|
||||
|
||||
var KeyMap = {};
|
||||
|
||||
for (var key in KeyCodes)
|
||||
{
|
||||
KeyMap[KeyCodes[key]] = key;
|
||||
}
|
||||
|
||||
module.exports = KeyMap;
|
|
@ -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,6 +338,8 @@ var SceneManager = new Class({
|
|||
{
|
||||
if (scene.create)
|
||||
{
|
||||
scene.sys.settings.status = CONST.CREATING;
|
||||
|
||||
scene.create.call(scene, scene.sys.settings.data);
|
||||
}
|
||||
|
||||
|
@ -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]
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
@ -43,10 +44,18 @@ var ScenePlugin = new Class({
|
|||
if (key === undefined) { key = this.key; }
|
||||
|
||||
if (key !== this.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;
|
||||
},
|
||||
|
@ -63,9 +72,16 @@ var ScenePlugin = new Class({
|
|||
launch: function (key, data)
|
||||
{
|
||||
if (key && key !== this.key)
|
||||
{
|
||||
if (this.settings.status !== CONST.RUNNING)
|
||||
{
|
||||
this.manager.queueOp('start', key);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.manager.start(key);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
@ -114,9 +130,16 @@ var ScenePlugin = new Class({
|
|||
switch: function (key)
|
||||
{
|
||||
if (key !== this.key)
|
||||
{
|
||||
if (this.settings.status !== CONST.RUNNING)
|
||||
{
|
||||
this.manager.queueOp('switch', this.key, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.manager.switch(this.key, key);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
||||
};
|
||||
|
|
|
@ -120,7 +120,7 @@ var Clock = new Class({
|
|||
return;
|
||||
}
|
||||
|
||||
delta * this.timeScale;
|
||||
delta *= this.timeScale;
|
||||
|
||||
for (var i = 0; i < this._active.length; i++)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue