Skip to content

Commit 2faab9b

Browse files
committed
added clone and setTo functions
1 parent 7ae5657 commit 2faab9b

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

src/geom/Polygon.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ Phaser.Polygon = function (points) {
5353
Phaser.Polygon.prototype = {
5454

5555
/**
56-
* Creates a clone of this polygon.
57-
*
58-
* @method Phaser.Polygon#clone
59-
* @return {Phaser.Polygon} A copy of the polygon.
60-
*/
61-
clone: function () {
56+
* Creates a copy of the given Polygon.
57+
* This is a deep clone, the resulting copy contains new Phaser.Point objects
58+
*
59+
* @method Phaser.Polygon#clone
60+
* @param {Phaser.Polygon} [output] Optional Polygon object. If given the values will be set into this object, otherwise a brand new Polygon object will be created and returned.
61+
* @return {Phaser.Polygon} The new Polygon object.
62+
*/
63+
clone: function (output) {
6264

6365
var points = [];
6466

@@ -67,7 +69,16 @@ Phaser.Polygon.prototype = {
6769
points.push(this.points[i].clone());
6870
}
6971

70-
return new Phaser.Polygon(points);
72+
if (typeof output === "undefined" || output === null)
73+
{
74+
output = new Phaser.Polygon(points);
75+
}
76+
else
77+
{
78+
output.setTo(points);
79+
}
80+
81+
return output;
7182

7283
},
7384

@@ -101,6 +112,14 @@ Phaser.Polygon.prototype = {
101112

102113
return inside;
103114

115+
},
116+
117+
setTo : function(points) {
118+
119+
this.points = point;
120+
121+
return this;
122+
104123
}
105124

106125
};

0 commit comments

Comments
 (0)