add limit function to Point

This commit is contained in:
Nick Aversano 2016-12-21 03:16:46 -05:00
parent 2c41814496
commit 9757d8341d

View file

@ -374,6 +374,24 @@ Phaser.Point.prototype = {
},
/**
* Alters the Point object so it's magnitude is at most the max value.
*
* @method Phaser.Point#limit
* @param {number} max - The maximum magnitude for the Point.
* @return {Phaser.Point} This Point object.
*/
limit: function (max) {
if (this.getMagnitudeSq() > max * max)
{
this.setMagnitude(max);
}
return this;
},
/**
* Determine if this point is at 0,0.
*