mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
Tidying: making it easier to access collision objects from a tile
This commit is contained in:
parent
806c9d3237
commit
8adce2ed2e
4 changed files with 26 additions and 3 deletions
|
@ -139,6 +139,14 @@ var Tile = new Class({
|
|||
*/
|
||||
this.collideDown = false;
|
||||
|
||||
/**
|
||||
* An array of collision objects from Tiled. These are defined on the tileset. Each tile
|
||||
* just gets a references to the objects stored in the tileset, so this is readonly.
|
||||
* @property {array|null} collisionObjects
|
||||
* @readonly
|
||||
*/
|
||||
this.collisionObjects = null;
|
||||
|
||||
/**
|
||||
* Whether the tile's left edge is interesting for collisions.
|
||||
* @property {boolean} faceLeft
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var Extend = require('../../../../utils/object/Extend');
|
||||
var GetValue = require('../../../../utils/object/GetValue');
|
||||
|
||||
// Copy properties from tileset to tiles
|
||||
var AssignTileProperties = function (mapData)
|
||||
|
@ -46,6 +47,17 @@ var AssignTileProperties = function (mapData)
|
|||
tile.properties, set.tileProperties[tile.index - set.firstgid]
|
||||
);
|
||||
}
|
||||
|
||||
// If that tile type has any collision info, add that to the tile object
|
||||
if (set.tileData && set.tileData[tile.index - set.firstgid])
|
||||
{
|
||||
var tileData = set.tileData[tile.index - set.firstgid];
|
||||
var objects = GetValue(tileData, 'objectgroup.objects', null);
|
||||
if (objects && objects.length > 0)
|
||||
{
|
||||
tile.collisionObjects = objects;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ var GetFastValue = require('../../../../utils/object/GetFastValue');
|
|||
var ParseObject = require('./ParseObject');
|
||||
|
||||
// Objects & Collision Data (polylines, etc)
|
||||
var ParseTilesets = function (json)
|
||||
var ParseObjectLayers = function (json)
|
||||
{
|
||||
var objects = {};
|
||||
var collision = {};
|
||||
|
@ -36,4 +36,4 @@ var ParseTilesets = function (json)
|
|||
return { objects: objects, collision: collision };
|
||||
};
|
||||
|
||||
module.exports = ParseTilesets;
|
||||
module.exports = ParseObjectLayers;
|
||||
|
|
|
@ -40,7 +40,10 @@ var ParseTilesets = function (json)
|
|||
var objectGroup = newSet.tileData[stringID].objectgroup;
|
||||
if (objectGroup && objectGroup.objects)
|
||||
{
|
||||
objectGroup.objects = objectGroup.objects.map(ParseObject);
|
||||
var parsedObjects = objectGroup.objects.map(
|
||||
function (obj) { return ParseObject(obj); }
|
||||
);
|
||||
newSet.tileData[stringID].objectgroup.objects = parsedObjects;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue