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

[1.2] Added Phaser.Math.setPhysicsPixelRatio() #424

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/math/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ Phaser.Math = {

/**
* = 2 π
* @method Phaser.Math#PI2
* @property Phaser.Math#PI2
*/
PI2: Math.PI * 2,

/**
* Two number are fuzzyEqual if their difference is less than ε.
* = -20 pixels
* @property Phaser.Math._pxRatio
* @protected
*/
_pxRatio: -20,

/**
* = -0.05 physics units
* @property Phaser.Math._pRatio
* @protected
*/
_pRatio: -0.05,

/**
* @method Phaser.Math#fuzzyEqual
* @param {number} a
* @param {number} b
Expand Down Expand Up @@ -1299,7 +1313,7 @@ Phaser.Math = {
* @return {number} The scaled value.
*/
p2px: function (v) {
return v *= -20;
return v *= Phaser.Math._pxRatio;
},

/**
Expand All @@ -1310,7 +1324,18 @@ Phaser.Math = {
* @return {number} The scaled value.
*/
px2p: function (v) {
return v * -0.05;
return v * Phaser.Math._pRatio;
},

/**
* Sets the pixel / p2 physics conversion scale.
*
* @method Phaser.Math#setPhysicsPixelRatio
* @param {number} ratio - The number of pixels per physics distance unit.
*/
setPhysicsPixelRatio: function(ratio) {
Phaser.Math._pxRatio = -ratio;
Phaser.Math._pRatio = -1 / ratio;
},

/**
Expand Down
4 changes: 2 additions & 2 deletions src/physics/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ Phaser.Physics.Body.prototype = {
*/
p2px: function (v) {

return v *= -20;
return this.game.math.p2px(v);

},

Expand All @@ -697,7 +697,7 @@ Phaser.Physics.Body.prototype = {
*/
px2p: function (v) {

return v * -0.05;
return this.game.math.px2p(v);

}

Expand Down