@@ -45,7 +45,7 @@ Phaser.Physics.Body = function (game, sprite, x, y, mass) {
4545 * @property {p2.Body } data - The p2 Body data.
4646 * @protected
4747 */
48- this . data = new p2 . Body ( { position :[ this . px2p ( x ) , this . px2p ( y ) ] , mass : mass } ) ;
48+ this . data = new p2 . Body ( { position :[ this . px2pi ( x ) , this . px2pi ( y ) ] , mass : mass } ) ;
4949 this . data . parent = this ;
5050
5151 /**
@@ -419,7 +419,7 @@ Phaser.Physics.Body.prototype = {
419419 */
420420 rotateLeft : function ( speed ) {
421421
422- this . data . angularVelocity = this . px2p ( speed ) ;
422+ this . data . angularVelocity = this . px2p ( - speed ) ;
423423
424424 } ,
425425
@@ -431,7 +431,7 @@ Phaser.Physics.Body.prototype = {
431431 */
432432 rotateRight : function ( speed ) {
433433
434- this . data . angularVelocity = this . px2p ( - speed ) ;
434+ this . data . angularVelocity = this . px2p ( speed ) ;
435435
436436 } ,
437437
@@ -444,7 +444,7 @@ Phaser.Physics.Body.prototype = {
444444 */
445445 moveForward : function ( speed ) {
446446
447- var magnitude = this . px2p ( - speed ) ;
447+ var magnitude = this . px2pi ( - speed ) ;
448448 var angle = this . data . angle + Math . PI / 2 ;
449449
450450 this . data . velocity [ 0 ] = magnitude * Math . cos ( angle ) ;
@@ -461,7 +461,7 @@ Phaser.Physics.Body.prototype = {
461461 */
462462 moveBackward : function ( speed ) {
463463
464- var magnitude = this . px2p ( - speed ) ;
464+ var magnitude = this . px2pi ( - speed ) ;
465465 var angle = this . data . angle + Math . PI / 2 ;
466466
467467 this . data . velocity [ 0 ] = - ( magnitude * Math . cos ( angle ) ) ;
@@ -478,7 +478,7 @@ Phaser.Physics.Body.prototype = {
478478 */
479479 thrust : function ( speed ) {
480480
481- var magnitude = this . px2p ( - speed ) ;
481+ var magnitude = this . px2pi ( - speed ) ;
482482 var angle = this . data . angle + Math . PI / 2 ;
483483
484484 this . data . force [ 0 ] += magnitude * Math . cos ( angle ) ;
@@ -495,7 +495,7 @@ Phaser.Physics.Body.prototype = {
495495 */
496496 reverse : function ( speed ) {
497497
498- var magnitude = this . px2p ( - speed ) ;
498+ var magnitude = this . px2pi ( - speed ) ;
499499 var angle = this . data . angle + Math . PI / 2 ;
500500
501501 this . data . force [ 0 ] -= magnitude * Math . cos ( angle ) ;
@@ -512,7 +512,7 @@ Phaser.Physics.Body.prototype = {
512512 */
513513 moveLeft : function ( speed ) {
514514
515- this . data . velocity [ 0 ] = this . px2p ( - speed ) ;
515+ this . data . velocity [ 0 ] = this . px2pi ( - speed ) ;
516516
517517 } ,
518518
@@ -525,7 +525,7 @@ Phaser.Physics.Body.prototype = {
525525 */
526526 moveRight : function ( speed ) {
527527
528- this . data . velocity [ 0 ] = this . px2p ( speed ) ;
528+ this . data . velocity [ 0 ] = this . px2pi ( speed ) ;
529529
530530 } ,
531531
@@ -538,7 +538,7 @@ Phaser.Physics.Body.prototype = {
538538 */
539539 moveUp : function ( speed ) {
540540
541- this . data . velocity [ 1 ] = this . px2p ( - speed ) ;
541+ this . data . velocity [ 1 ] = this . px2pi ( - speed ) ;
542542
543543 } ,
544544
@@ -551,7 +551,7 @@ Phaser.Physics.Body.prototype = {
551551 */
552552 moveDown : function ( speed ) {
553553
554- this . data . velocity [ 1 ] = this . px2p ( speed ) ;
554+ this . data . velocity [ 1 ] = this . px2pi ( speed ) ;
555555
556556 } ,
557557
@@ -572,8 +572,8 @@ Phaser.Physics.Body.prototype = {
572572 */
573573 postUpdate : function ( ) {
574574
575- this . sprite . x = this . p2px ( this . data . position [ 0 ] ) ;
576- this . sprite . y = this . p2px ( this . data . position [ 1 ] ) ;
575+ this . sprite . x = this . p2pxi ( this . data . position [ 0 ] ) ;
576+ this . sprite . y = this . p2pxi ( this . data . position [ 1 ] ) ;
577577
578578 if ( ! this . fixedRotation )
579579 {
@@ -695,7 +695,7 @@ Phaser.Physics.Body.prototype = {
695695 if ( typeof offsetY === 'undefined' ) { offsetY = 0 ; }
696696 if ( typeof rotation === 'undefined' ) { rotation = 0 ; }
697697
698- this . data . addShape ( shape , [ this . px2p ( offsetX ) , this . px2p ( offsetY ) ] , rotation ) ;
698+ this . data . addShape ( shape , [ this . px2pi ( offsetX ) , this . px2pi ( offsetY ) ] , rotation ) ;
699699
700700 return shape ;
701701
@@ -950,10 +950,6 @@ Phaser.Physics.Body.prototype = {
950950
951951 if ( typeof sprite === 'undefined' ) { sprite = this . sprite ; }
952952
953- // because Sprite.phyicsEnabled = true now sets anchor to 0.5
954- // var px = (sprite.width / 2) + (-sprite.width * sprite.anchor.x);
955- // var py = (sprite.height / 2) + (-sprite.height * sprite.anchor.y);
956-
957953 this . clearShapes ( ) ;
958954
959955 return this . addRectangle ( sprite . width , sprite . height , 0 , 0 , sprite . rotation ) ;
@@ -1046,25 +1042,51 @@ Phaser.Physics.Body.prototype = {
10461042 /**
10471043 * Convert p2 physics value (meters) to pixel scale.
10481044 *
1049- * @method Phaser.Math #p2px
1045+ * @method Phaser.Physics.Body #p2px
10501046 * @param {number } v - The value to convert.
10511047 * @return {number } The scaled value.
10521048 */
10531049 p2px : function ( v ) {
10541050
1055- return v *= - 20 ;
1051+ return v *= 20 ;
10561052
10571053 } ,
10581054
10591055 /**
10601056 * Convert pixel value to p2 physics scale (meters).
10611057 *
1062- * @method Phaser.Math #px2p
1058+ * @method Phaser.Physics.Body #px2p
10631059 * @param {number } v - The value to convert.
10641060 * @return {number } The scaled value.
10651061 */
10661062 px2p : function ( v ) {
10671063
1064+ return v * 0.05 ;
1065+
1066+ } ,
1067+
1068+ /**
1069+ * Convert p2 physics value (meters) to pixel scale and inverses it.
1070+ *
1071+ * @method Phaser.Physics.Body#p2pxi
1072+ * @param {number } v - The value to convert.
1073+ * @return {number } The scaled value.
1074+ */
1075+ p2pxi : function ( v ) {
1076+
1077+ return v *= - 20 ;
1078+
1079+ } ,
1080+
1081+ /**
1082+ * Convert pixel value to p2 physics scale (meters) and inverses it.
1083+ *
1084+ * @method Phaser.Physics.Body#px2pi
1085+ * @param {number } v - The value to convert.
1086+ * @return {number } The scaled value.
1087+ */
1088+ px2pi : function ( v ) {
1089+
10681090 return v * - 0.05 ;
10691091
10701092 }
0 commit comments