Skip to content

Commit d67e902

Browse files
committed
Rectangle.getPoint is a new method that returns a point based on the given location constant, such as Phaser.BOTTOM_LEFT. It returns the same result as calling Rectangle.bottomLeft (etc) but unlike those getters you are able to provide your own Point object.
1 parent 64a44aa commit d67e902

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
366366
* BitmapData.copyTransform allows you to draw a Game Object to the BitmapData, using its `worldTransform` property to control the location, scaling and rotation of the object. You can optionally provide
367367
* BitmapData.drawGroup now uses the new `copyTransform` method, to provide for far more accurate results. Previously nested Game Objects wouldn't render correctly, nor would Sprites added via `addChild` to another Sprite. BitmapText objects also rendered without rotation taken into account, and the Sprites smoothing property was ignored. All of these things are now covered by the new drawGroup method, which also handles full deep iteration down the display list.
368368
* Added the following new constants: `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.MIDDLE_LEFT`, `Phaser.MIDDLE_CENTER`, `Phaser.MIDDLE_RIGHT`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
369+
* Rectangle.getPoint is a new method that returns a point based on the given location constant, such as `Phaser.BOTTOM_LEFT`. It returns the same result as calling `Rectangle.bottomLeft` (etc) but unlike those getters you are able to provide your own Point object.
369370

370371
### Updates
371372

src/geom/Rectangle.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,70 @@ Phaser.Rectangle.prototype = {
383383

384384
},
385385

386+
/**
387+
* Returns a point based on the given location constant.
388+
*
389+
* Which can be one of:
390+
*
391+
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.MIDDLE_LEFT`,
392+
* `Phaser.MIDDLE_CENTER`, `Phaser.MIDDLE_RIGHT`, `Phaser.BOTTOM_LEFT`,
393+
* `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
394+
*
395+
* This method returns the same values as calling Rectangle.bottomLeft, etc, but those
396+
* calls always create a new Point object, where-as this one allows you to use your own.
397+
*
398+
* @method Phaser.Rectangle#getPoint
399+
* @param {integer} [location] - One of the Phaser location constants, such as `Phaser.TOP_RIGHT`.
400+
* @param {Phaser.Point} [out] - A Phaser.Point that the values will be set in.
401+
* If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object.
402+
* @return {Phaser.Point} An object containing the point in its `x` and `y` properties.
403+
*/
404+
getPoint: function (location, out) {
405+
406+
if (out === undefined) { out = new Phaser.Point(); }
407+
408+
switch (location)
409+
{
410+
default:
411+
case Phaser.TOP_LEFT:
412+
return out.set(this.x, this.y);
413+
break;
414+
415+
case Phaser.TOP_CENTER:
416+
return out.set(this.centerX, this.y);
417+
break;
418+
419+
case Phaser.TOP_RIGHT:
420+
return out.set(this.right, this.y);
421+
break;
422+
423+
case Phaser.MIDDLE_LEFT:
424+
return out.set(this.x, this.centerY);
425+
break;
426+
427+
case Phaser.MIDDLE_CENTER:
428+
return out.set(this.centerX, this.centerY);
429+
break;
430+
431+
case Phaser.MIDDLE_RIGHT:
432+
return out.set(this.right, this.centerY);
433+
break;
434+
435+
case Phaser.BOTTOM_LEFT:
436+
return out.set(this.x, this.bottom);
437+
break;
438+
439+
case Phaser.BOTTOM_CENTER:
440+
return out.set(this.centerX, this.bottom);
441+
break;
442+
443+
case Phaser.BOTTOM_RIGHT:
444+
return out.set(this.right, this.bottom);
445+
break;
446+
}
447+
448+
},
449+
386450
/**
387451
* Returns a string representation of this object.
388452
* @method Phaser.Rectangle#toString

0 commit comments

Comments
 (0)