World.setBounds if called after you had already started P2 Physics would incorrectly create a new collision group for the wall objects. P2.World now remembers the settings you provide for each wall and the collision group, and re-applies these settings should the world dimensions ever change (thanks @nextht #1455)

This commit is contained in:
photonstorm 2015-02-11 22:33:29 +00:00
parent b692d3b456
commit f60b2b7635
2 changed files with 48 additions and 6 deletions

View file

@ -152,8 +152,9 @@ Thanks to @pnstickne for vast majority of this update.
* Timer.update was calling the TimerEvent callback even if `TimerEvent.pendingDelete` was already set to `true`, causing timer events to stack-up in cases where a new TimerEvent was generated in the callback (thanks @clowerweb #838)
* Pointer.stop would call `event.preventDefault` if `Pointer._stateReset` was `true`, which is always `true` after a State has changed and before Pointer.start has been called. However this broken interacting with DOM elements in the case where the State changes and you immediately try to use the DOM element without first having clicked on the Phaser game. An additional guard was added so `preventDefault` will now only be called if both `_stateReste` and `Pointer.withinGame` are true (thanks @satan6 #1509)
* Group.forEach (and many other Group methods) now uses the `children.length` value directly instead of caching it, which both helps performance and stops the loop from breaking should you remove a Group child in the invoked callback.
* Phaser.Ellipse.contains is now working again (thanks @spayton)
* Phaser.Ellipse.contains is now working again (thanks @spayton #1524)
* PIXI.WebGLRenderer.destroy has been fixed to decrement the `glContextId` and remove it from the PIXI.instances global. `Game.destroy` now hooks into this. This now means that you can now delete and create your Phaser game over and over without it crashing WebGL after the 4th attempt (#1260)
* World.setBounds if called after you had already started P2 Physics would incorrectly create a new collision group for the wall objects. P2.World now remembers the settings you provide for each wall and the collision group, and re-applies these settings should the world dimensions ever change (thanks @nextht #1455)
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).

View file

@ -197,6 +197,36 @@ Phaser.Physics.P2 = function (game, config) {
*/
this._collisionGroupID = 2;
/**
* @property {boolean} _boundsLeft - Internal var that keeps track of world bounds settings.
* @private
*/
this._boundsLeft = true;
/**
* @property {boolean} _boundsRight - Internal var that keeps track of world bounds settings.
* @private
*/
this._boundsRight = true;
/**
* @property {boolean} _boundsTop - Internal var that keeps track of world bounds settings.
* @private
*/
this._boundsTop = true;
/**
* @property {boolean} _boundsBottom - Internal var that keeps track of world bounds settings.
* @private
*/
this._boundsBottom = true;
/**
* @property {boolean} _boundsOwnGroup - Internal var that keeps track of world bounds settings.
* @private
*/
this._boundsOwnGroup = false;
// By default we want everything colliding with everything
this.setBoundsToWorld(true, true, true, true, false);
@ -560,6 +590,10 @@ Phaser.Physics.P2.prototype = {
/**
* Sets the bounds of the Physics world to match the given world pixel dimensions.
* You can optionally set which 'walls' to create: left, right, top or bottom.
* If none of the walls are given it will default to use the walls settings it had previously.
* I.e. if you previously told it to not have the left or right walls, and you then adjust the world size
* the newly created bounds will also not have the left and right walls.
* Explicitly state them in the parameters to override this.
*
* @method Phaser.Physics.P2#setBounds
* @param {number} x - The x coordinate of the top-left corner of the bounds.
@ -574,11 +608,11 @@ Phaser.Physics.P2.prototype = {
*/
setBounds: function (x, y, width, height, left, right, top, bottom, setCollisionGroup) {
if (typeof left === 'undefined') { left = true; }
if (typeof right === 'undefined') { right = true; }
if (typeof top === 'undefined') { top = true; }
if (typeof bottom === 'undefined') { bottom = true; }
if (typeof setCollisionGroup === 'undefined') { setCollisionGroup = true; }
if (typeof left === 'undefined') { left = this._boundsLeft; }
if (typeof right === 'undefined') { right = this._boundsRight; }
if (typeof top === 'undefined') { top = this._boundsTop; }
if (typeof bottom === 'undefined') { bottom = this._boundsBottom; }
if (typeof setCollisionGroup === 'undefined') { setCollisionGroup = this._boundsOwnGroup; }
if (this.walls.left)
{
@ -652,6 +686,13 @@ Phaser.Physics.P2.prototype = {
this.world.addBody(this.walls.bottom);
}
// Remember the bounds settings in case they change later on via World.setBounds
this._boundsLeft = left;
this._boundsRight = right;
this._boundsTop = top;
this._boundsBottom = bottom;
this._boundsOwnGroup = setCollisionGroup;
},
/**