Skip to content

Commit 7ee0c20

Browse files
committed
Added Debug.renderSpriteBounds() back and wrapped Body.velocity and force in px2p calls.
1 parent d7ababa commit 7ee0c20

5 files changed

Lines changed: 30 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Updates:
136136
* Added hostname: '*' to the grunt-connect in Gruntfile.js (fixes #426)
137137
* Device, Canvas and GamePad classes all updated for better CocoonJS support (thanks Videlais)
138138
* BitmapData.alphaMask will draw the given image onto a BitmapData using an image as an alpha mask.
139+
* The new GameObjectCreator (which you access via game.make or State.make) lets you easily create an object but NOT add it to the display list.
139140

140141

141142
Bug Fixes:

src/physics/Body.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ Phaser.Physics.Body = function (game, sprite, x, y, mass) {
4949
this.data.parent = this;
5050

5151
/**
52-
* @property {Phaser.PointProxy} velocity - The velocity of the body. Set velocity.x to a negative value to move to the left, position to the right. velocity.y negative values move up, positive move down.
52+
* @property {Phaser.InversePointProxy} velocity - The velocity of the body. Set velocity.x to a negative value to move to the left, position to the right. velocity.y negative values move up, positive move down.
5353
*/
54-
this.velocity = new Phaser.Physics.PointProxy(this.data.velocity);
54+
this.velocity = new Phaser.Physics.InversePointProxy(this.game, this.data.velocity);
5555

5656
/**
57-
* @property {Phaser.PointProxy} force - The force applied to the body.
57+
* @property {Phaser.InversePointProxy} force - The force applied to the body.
5858
*/
59-
this.force = new Phaser.Physics.PointProxy(this.data.force);
59+
this.force = new Phaser.Physics.InversePointProxy(this.game, this.data.force);
6060

6161
/**
6262
* @property {Phaser.Point} gravity - A locally applied gravity force to the Body. Applied directly before the world step. NOTE: Not currently implemented.

src/physics/InversePointProxy.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
* @class Phaser.Physics.InversePointProxy
1111
* @classdesc InversePointProxy
1212
* @constructor
13+
* @param {Phaser.Game} game - A reference to the Phaser.Game instance.
1314
* @param {any} destination - The object to bind to.
1415
*/
15-
Phaser.Physics.InversePointProxy = function (destination) {
16+
Phaser.Physics.InversePointProxy = function (game, destination) {
1617

18+
this.game = game;
1719
this.destination = destination;
1820

1921
};
@@ -34,7 +36,7 @@ Object.defineProperty(Phaser.Physics.InversePointProxy.prototype, "x", {
3436

3537
set: function (value) {
3638

37-
this.destination[0] = -value;
39+
this.destination[0] = this.game.math.px2p(-value);
3840

3941
}
4042

@@ -54,7 +56,7 @@ Object.defineProperty(Phaser.Physics.InversePointProxy.prototype, "y", {
5456

5557
set: function (value) {
5658

57-
this.destination[1] = -value;
59+
this.destination[1] = this.game.math.px2p(-value);
5860

5961
}
6062

src/physics/PointProxy.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
* @class Phaser.Physics.PointProxy
1111
* @classdesc PointProxy
1212
* @constructor
13+
* @param {Phaser.Game} game - A reference to the Phaser.Game instance.
1314
* @param {any} destination - The object to bind to.
1415
*/
15-
Phaser.Physics.PointProxy = function (destination) {
16+
Phaser.Physics.PointProxy = function (game, destination) {
1617

18+
this.game = game;
1719
this.destination = destination;
1820

1921
};
@@ -34,7 +36,7 @@ Object.defineProperty(Phaser.Physics.PointProxy.prototype, "x", {
3436

3537
set: function (value) {
3638

37-
this.destination[0] = value;
39+
this.destination[0] = this.game.math.px2p(value);
3840

3941
}
4042

@@ -54,7 +56,7 @@ Object.defineProperty(Phaser.Physics.PointProxy.prototype, "y", {
5456

5557
set: function (value) {
5658

57-
this.destination[1] = value;
59+
this.destination[1] = this.game.math.px2p(value);
5860

5961
}
6062

src/utils/Debug.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,21 @@ Phaser.Utils.Debug.prototype = {
350350

351351
},
352352

353+
/**
354+
* Renders the Sprites bounds. Note: This is really expensive as it has to calculate the bounds every time you call it!
355+
* @method Phaser.Utils.Debug#renderSpriteBounds
356+
* @param {Phaser.Sprite} sprite - Description.
357+
* @param {string} [color] - Color of the debug info to be rendered (format is css color string).
358+
* @param {boolean} [filled=true] - Render the rectangle as a fillRect (default, true) or a strokeRect (false)
359+
*/
360+
renderSpriteBounds: function (sprite, color, filled) {
361+
362+
var bounds = sprite.getBounds();
363+
364+
this.renderRectangle(bounds, color, filled);
365+
366+
},
367+
353368
/**
354369
* Render debug infos (including name, bounds info, position and some other properties) about the Sprite.
355370
* @method Phaser.Utils.Debug#renderSpriteInfo

0 commit comments

Comments
 (0)