mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 22:48:34 +00:00
Path can now be constructed via fromJSON.
This commit is contained in:
parent
0e69dccabf
commit
0c5df6df80
1 changed files with 60 additions and 1 deletions
|
@ -21,6 +21,9 @@ var Path = new Class({
|
||||||
|
|
||||||
function Path (x, y)
|
function Path (x, y)
|
||||||
{
|
{
|
||||||
|
if (x === undefined) { x = 0; }
|
||||||
|
if (y === undefined) { y = 0; }
|
||||||
|
|
||||||
this.name = '';
|
this.name = '';
|
||||||
|
|
||||||
this.curves = [];
|
this.curves = [];
|
||||||
|
@ -30,7 +33,16 @@ var Path = new Class({
|
||||||
// Automatically closes the path
|
// Automatically closes the path
|
||||||
this.autoClose = false;
|
this.autoClose = false;
|
||||||
|
|
||||||
this.startPoint = new Vector2(x, y);
|
this.startPoint = new Vector2();
|
||||||
|
|
||||||
|
if (typeof x === 'object')
|
||||||
|
{
|
||||||
|
this.fromJSON(x);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.startPoint.set(x, y);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
moveTo: function (x, y)
|
moveTo: function (x, y)
|
||||||
|
@ -149,6 +161,53 @@ var Path = new Class({
|
||||||
return out;
|
return out;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert JSON
|
||||||
|
*
|
||||||
|
* @method fromJSON
|
||||||
|
*
|
||||||
|
* @param {[type]} data [description]
|
||||||
|
*
|
||||||
|
* @return {[type]} [description]
|
||||||
|
*/
|
||||||
|
fromJSON: function (data)
|
||||||
|
{
|
||||||
|
// data should be an object matching the Path.toJSON object structure.
|
||||||
|
|
||||||
|
this.curves = [];
|
||||||
|
this.cacheLengths = [];
|
||||||
|
|
||||||
|
this.startPoint.set(data.x, data.y);
|
||||||
|
|
||||||
|
this.autoClose = data.autoClose;
|
||||||
|
|
||||||
|
for (var i = 0; i < data.curves.length; i++)
|
||||||
|
{
|
||||||
|
var curve = data.curves[i];
|
||||||
|
|
||||||
|
switch (curve.type)
|
||||||
|
{
|
||||||
|
case 'LineCurve':
|
||||||
|
this.add(LineCurve.fromJSON(curve));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'EllipseCurve':
|
||||||
|
this.add(EllipseCurve.fromJSON(curve));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'SplineCurve':
|
||||||
|
this.add(SplineCurve.fromJSON(curve));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'CubicBezierCurve':
|
||||||
|
this.add(CubicBezierCurve.fromJSON(curve));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
toJSON: function ()
|
toJSON: function ()
|
||||||
{
|
{
|
||||||
var out = [];
|
var out = [];
|
||||||
|
|
Loading…
Add table
Reference in a new issue