Polygon.setTo can now take a string of space separated numbers when creating the polygon data, i.e.: '40 0 40 20 100 20 100 80 40 80 40 100 0 50'. This update also impacts the Polygon Shape object, which can now also take this format as well.

This commit is contained in:
Richard Davey 2018-09-26 11:01:48 +01:00
parent ef3f6c0348
commit 684838aabe
3 changed files with 11 additions and 3 deletions

View file

@ -8,6 +8,7 @@
* The Loader has been updated to handle the impact of you destroying the game instance while still processing files. It will no longer throw cache and texture related errors. Fix #4049 (thanks @pantoninho) * The Loader has been updated to handle the impact of you destroying the game instance while still processing files. It will no longer throw cache and texture related errors. Fix #4049 (thanks @pantoninho)
* `TileSet.getTileData()` has been updated so it will return tile data from either Tiled 1.1.x or the new Tiled 1.2.x JSON structure. Fix #3998 (thanks @martin-pabst @halgorithm) * `TileSet.getTileData()` has been updated so it will return tile data from either Tiled 1.1.x or the new Tiled 1.2.x JSON structure. Fix #3998 (thanks @martin-pabst @halgorithm)
* `Polygon.setTo` can now take a string of space separated numbers when creating the polygon data, i.e.: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'`. This update also impacts the Polygon Shape object, which can now also take this format as well.
### Bug Fixes ### Bug Fixes

View file

@ -24,6 +24,7 @@ var Smooth = require('../../../geom/polygon/Smooth');
* The Polygon Shape is created by providing a list of points, which are then used to create an * The Polygon Shape is created by providing a list of points, which are then used to create an
* internal Polygon geometry object. The points can be set from a variety of formats: * internal Polygon geometry object. The points can be set from a variety of formats:
* *
* - A string containing paired values separated by a single space: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'`
* - An array of Point or Vector2 objects: `[new Phaser.Math.Vec2(x1, y1), ...]` * - An array of Point or Vector2 objects: `[new Phaser.Math.Vec2(x1, y1), ...]`
* - An array of objects with public x/y properties: `[obj1, obj2, ...]` * - An array of objects with public x/y properties: `[obj1, obj2, ...]`
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]` * - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`

View file

@ -71,6 +71,7 @@ var Polygon = new Class({
* *
* The points can be set from a variety of formats: * The points can be set from a variety of formats:
* *
* - A string containing paired values separated by a single space: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'`
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]` * - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
* - An array of objects with public x/y properties: `[obj1, obj2, ...]` * - An array of objects with public x/y properties: `[obj1, obj2, ...]`
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]` * - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
@ -90,6 +91,11 @@ var Polygon = new Class({
this.area = 0; this.area = 0;
this.points = []; this.points = [];
if (typeof points === 'string')
{
points = points.split(' ');
}
if (!Array.isArray(points)) if (!Array.isArray(points))
{ {
return this; return this;
@ -103,10 +109,10 @@ var Polygon = new Class({
{ {
p = { x: 0, y: 0 }; p = { x: 0, y: 0 };
if (typeof points[i] === 'number') if (typeof points[i] === 'number' || typeof points[i] === 'string')
{ {
p.x = points[i]; p.x = parseFloat(points[i]);
p.y = points[i + 1]; p.y = parseFloat(points[i + 1]);
i++; i++;
} }
else if (Array.isArray(points[i])) else if (Array.isArray(points[i]))