|
15 | 15 | * @param {number} [width=0] - The overall width of this ellipse. |
16 | 16 | * @param {number} [height=0] - The overall height of this ellipse. |
17 | 17 | */ |
18 | | -Phaser.Ellipse = function (x, y, width, height) { |
19 | | - |
| 18 | +Phaser.Ellipse = function (x, y, width, height) |
| 19 | +{ |
20 | 20 | x = x || 0; |
21 | 21 | y = y || 0; |
22 | 22 | width = width || 0; |
@@ -176,6 +176,30 @@ Phaser.Ellipse.prototype = { |
176 | 176 |
|
177 | 177 | }, |
178 | 178 |
|
| 179 | + /** |
| 180 | + * Returns a Point object containing the coordinates of a point on the circumference of the ellipse based on the given angle. |
| 181 | + * |
| 182 | + * @method Phaser.Ellipse#circumferencePoint |
| 183 | + * @param {number} angle - The angle in radians (unless asDegrees is true) to return the point from. |
| 184 | + * @param {boolean} [asDegrees=false] - Is the given angle in radians (false) or degrees (true)? |
| 185 | + * @param {Phaser.Point} [out] - An optional Point object to put the result in to. If none specified a new Point object will be created. |
| 186 | + * @return {Phaser.Point} The Point object holding the result. |
| 187 | + */ |
| 188 | + circumferencePoint: function (angle, asDegrees, out) |
| 189 | + { |
| 190 | + if (out === undefined) { out = new Phaser.Point(); } |
| 191 | + |
| 192 | + if (asDegrees) |
| 193 | + { |
| 194 | + angle = Phaser.Math.degToRad(angle); |
| 195 | + } |
| 196 | + |
| 197 | + out.x = this.x + (this.width * Math.cos(angle)); |
| 198 | + out.y = this.y + (this.height * Math.sin(angle)); |
| 199 | + |
| 200 | + return out; |
| 201 | + }, |
| 202 | + |
179 | 203 | /** |
180 | 204 | * Returns a string representation of this object. |
181 | 205 | * @method Phaser.Ellipse#toString |
@@ -305,9 +329,10 @@ Object.defineProperty(Phaser.Ellipse.prototype, "empty", { |
305 | 329 | * @param {number} y - The Y value of the coordinate to test. |
306 | 330 | * @return {boolean} True if the coordinates are within this ellipse, otherwise false. |
307 | 331 | */ |
308 | | -Phaser.Ellipse.contains = function (a, x, y) { |
309 | | - |
310 | | - if (a.width <= 0 || a.height <= 0) { |
| 332 | +Phaser.Ellipse.contains = function (a, x, y) |
| 333 | +{ |
| 334 | + if (a.width <= 0 || a.height <= 0) |
| 335 | + { |
311 | 336 | return false; |
312 | 337 | } |
313 | 338 |
|
|
0 commit comments