mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 04:33:31 +00:00
Add Impact method for loading collision map from Weltmeister file
This commit is contained in:
parent
821eae6eee
commit
fd8cad1fb6
1 changed files with 51 additions and 7 deletions
|
@ -9,6 +9,7 @@ var GetFastValue = require('../../utils/object/GetFastValue');
|
|||
var Set = require('../../structs/Set');
|
||||
var Solver = require('./Solver');
|
||||
var TYPE = require('./TYPE');
|
||||
var TILEMAP_FORMATS = require('../../gameobjects/tilemap/Formats');
|
||||
|
||||
var World = new Class({
|
||||
|
||||
|
@ -95,9 +96,52 @@ var World = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
setCollisionMap: function (tilesize, data)
|
||||
/**
|
||||
* Sets the collision map for the world either from a Weltmeister JSON level in the cache or from
|
||||
* a 2D array. If loading from a Weltmeister level, the map must have a layer called "collision".
|
||||
*
|
||||
* @param {string|integer[][]} key - Either a string key that corresponds to a Weltmeister level
|
||||
* in the cache, or a 2D array of collision IDs.
|
||||
* @param {integer} tileSize - The size of a tile. This is optional if loading from a Weltmeister
|
||||
* level in the cache.
|
||||
* @return {CollisionMap|null} The newly created CollisionMap, or null if the method failed to
|
||||
* create the CollisionMap.
|
||||
*/
|
||||
setCollisionMap: function (key, tileSize)
|
||||
{
|
||||
this.collisionMap = new CollisionMap(tilesize, data);
|
||||
if (typeof key === 'string')
|
||||
{
|
||||
var tilemapData = this.scene.cache.tilemap.get(key);
|
||||
|
||||
if (!tilemapData || tilemapData.format !== TILEMAP_FORMATS.WELTMEISTER)
|
||||
{
|
||||
console.warn('The specified key does not correspond to a Weltmeister tilemap: ' + key);
|
||||
return null;
|
||||
}
|
||||
|
||||
var layers = tilemapData.data.layer;
|
||||
var collisionLayer;
|
||||
for (var i = 0; i < layers.length; i++)
|
||||
{
|
||||
if (layers[i].name === 'collision')
|
||||
{
|
||||
collisionLayer = layers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tileSize === undefined) { tileSize = collisionLayer.tilesize; }
|
||||
|
||||
this.collisionMap = new CollisionMap(tileSize, collisionLayer.data);
|
||||
}
|
||||
else if (Array.isArray(key))
|
||||
{
|
||||
this.collisionMap = new CollisionMap(tileSize, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Invalid Weltmeister collision map data: ' + key);
|
||||
}
|
||||
|
||||
return this.collisionMap;
|
||||
},
|
||||
|
@ -346,9 +390,9 @@ var World = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
//////////////
|
||||
// ////////////
|
||||
// Helpers //
|
||||
//////////////
|
||||
// ////////////
|
||||
|
||||
setCollidesNever: function (bodies)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue