Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add limit method on Phaser.Point #2927

Merged
merged 1 commit into from Dec 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions v2-community/src/geom/Point.js
Expand Up @@ -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.
*
Expand Down