Skip to content

Commit

Permalink
Keyboard.stop nulls the function references after removing the event …
Browse files Browse the repository at this point in the history
…listeners (thanks @bmceldowney, phaserjs#691)
  • Loading branch information
photonstorm committed Apr 7, 2014
1 parent bf32590 commit 01eec6c
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 46 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Version 2.0.3 - "Allorallen" - -in development-
Updated

* Updated to [Pixi.js 1.5.2](https://github.com/GoodBoyDigital/pixi.js/releases/tag/v1.5.2)
* Updated to [p2.js 0.5.0](https://github.com/schteppe/p2.js/releases/tag/v0.5.0)
* Return the result of P2.Body.setCircle for further chaining and manipulation (fix #659)
* Updated the PhysicsEditor plugin to maintain position, radius, mask bits, category bits and sensor flags (thanks @georgiee, #674)
* Further TypeScript defs tweaks (thanks @clark-stevenson)
Expand All @@ -75,6 +76,8 @@ Updated
* The Phaser Gruntfile is now split up into option tasks (thanks @xtian, #638)
* Key.reset now clears any callbacks associated with the onDown and onUp events and nulls the onHoldCallback if set. Key.reset is called by Keyboard.reset when changing state.
* If you pass `null` to Tilemap.putTile as the tile parameter it will pass the call over to Tilemap.removeTile.
* TypeScript definitions updated for latest changes (thanks @clark-stevenson)
* Keyboard.stop nulls the function references after removing the event listeners (thanks @bmceldowney, #691)


New Features
Expand Down Expand Up @@ -110,13 +113,67 @@ Bug Fixes
* Fixed bug in gl.bindTexture which tried to use an undefined private var. (@photonstorm) (pixi.js 1.5.2 bug fix)
* Fixed the 'short cut' version of Math.floor in setTransform if roundPixels is true. (@photonstorm) (pixi.js 1.5.2 bug fix)
* SoundManager.boot will check to see if the AudioContext was created before carrying on (thanks @keyle, fix #669)
* Fixed bug where move up and move down method in groups did not work (thanks @jonthulu, fix #684)
* Fixed bug in Group.next when cursor is at the last child (thanks @jonthulu, fix #688)


ToDo

* Split P2 world bounds into different bodies to help the broad phase.


p2.js v0.5.0

* Added property .enableIslandSleeping to World.
* Added property .useFrictionGravityOnZeroGravity to World.
* Renamed .useWorldGravityForFrictionApproximation in World to .useWorldGravityAsFrictionGravity to keep things more uniform.
* Sleep improvements.
* Added property .frictionIterations to GSSolver, and removed .skipFrictionIterations.
* Upgraded to gl-matrix 2.1.0.
* Removed QuadTree.
* Removed mat2.
* Added Utils.extend.
* Added methods .setStiffness and .setRelaxation methods to Constraint.
* Removed properties .stiffness, .relaxation and .useGlobalEquationParameters from GSSolver.
* Added methods .setGlobalStiffness, .setGlobalRelaxation, .setGlobalEquationParameters to World.
* Renamed property .eps to .epsilon for Equation.
* Removed property .useBoundingBoxes from NaiveBroadphase in favor of the new property .boundingVolumeType in Broadphase.
* Added methods .getMaxForce and .setMaxForce to LockConstraint.
* Changed property names .bi, .bj, .ni, .ri, .rj to .bodyA, .bodyB, .normalA, .contactPointA, .contactPointB in Equation, ContactEquation and FrictionEquation classes.
* Removed IslandSolver in favor of the new property World.islandSplit.
* Changed constructors of the Constraints so they all take an options object as last parameter.
* Added property .collideConnected to Constraint.
* Added property .islandSplit to World.
* Added methods .disableBodyCollision and .enableBodyCollision to World.
* Added properties .useWorldGravityForFrictionApproximation and .frictionGravity to World.
* Added Heightfield class.
* Removed properties .defaultFriction and .defaultRestitution from World, in favor of .defaultContactMaterial.
* Added property .enabled to Equation.
* Added property .surfaceVelocity to ContactMaterial.
* Added property .sensor to Shape.
* World now emits events 'beginContact', 'endContact' and 'preSolve'.
* Added property .gravityScale to Body.
* Renamed class SAP1DBroadphase to SAPBroadphase.
* Added property .interpolatedPosition to Body`.
* Added method .internalStep to World.
* Added property .applyGravity to World.
* Renamed method .computeC to .computeInvC in Equation, and made it compute the inverse.
* Added static method Utils.splice.
* Added property .world to Body.
* Added property .fixedRotation to Body.
* Added class AABB.
* Added properties .aabb and .aabbNeedsUpdate to Body, as well as a method .updateAABB.
* Added property .useBoundingBoxes to NaiveBroadphase.
* Added static method Broadphase.aabbCheck.
* Added method .computeAABB to Shape.
* Added static method Broadphase.canCollide.
* Body now inherits from EventEmitter, and dispatches events 'sleep','sleepy' and 'wakeup'.
* Added properties .allowSleep, .sleepState, .sleepSpeedLimit, .sleepTimeLimit, .lastTimeSleepy as well as methods .sleep, .wakeUp and .sleepTick to Body.
* Added enums Body.AWAKE, Body.SLEEPY, Body.SLEEPING.
* Added property .enableBodySleeping to World.
* Added options .disableRotationalLock, .lowerLimit, .upperLimit to PrismaticConstraint constructor.
* Added methods .enableMotor, .disableMotor to PrismaticConstraint as well as properties .motorEnabled, .motorSpeed, .motorEquation.


There is an extensive [Migration Guide](https://github.com/photonstorm/phaser/blob/master/resources/Migration%20Guide.md) available for those converting from Phaser 1.x to 2.x. In the guide we detail the API breaking changes and approach to our new physics system.

Expand Down
18 changes: 6 additions & 12 deletions src/core/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
this.physicsConfig = physicsConfig;

/**
* @property {HTMLElement} parent - The Games DOM parent.
* @property {string|HTMLElement} parent - The Games DOM parent.
* @default
*/
this.parent = '';
Expand Down Expand Up @@ -71,18 +71,17 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
this.antialias = true;

/**
* @property {number} renderer - The Pixi Renderer
* @default
* @property {PIXI.CanvasRenderer|PIXI.WebGLRenderer} renderer - The Pixi Renderer.
*/
this.renderer = Phaser.AUTO;
this.renderer = null;

/**
* @property {number} renderType - The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS or Phaser.WEBGL.
*/
this.renderType = Phaser.AUTO;

/**
* @property {number} state - The StateManager.
* @property {Phaser.StateManager} state - The StateManager.
*/
this.state = null;

Expand Down Expand Up @@ -115,19 +114,16 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant

/**
* @property {Phaser.Cache} cache - Reference to the assets cache.
* @default
*/
this.cache = null;

/**
* @property {Phaser.Input} input - Reference to the input manager
* @default
*/
this.input = null;

/**
* @property {Phaser.Loader} load - Reference to the assets loader.
* @default
*/
this.load = null;

Expand Down Expand Up @@ -187,7 +183,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
this.device = null;

/**
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
* @property {Phaser.Camera} camera - A handy reference to world.camera.
*/
this.camera = null;

Expand Down Expand Up @@ -219,7 +215,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
this.stepping = false;

/**
* @property {boolean} stepping - An internal property used by enableStep, but also useful to query from your own game objects.
* @property {boolean} pendingStep - An internal property used by enableStep, but also useful to query from your own game objects.
* @default
* @readonly
*/
Expand Down Expand Up @@ -255,14 +251,12 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
/**
* @property {boolean} _paused - Is game paused?
* @private
* @default
*/
this._paused = false;

/**
* @property {boolean} _codePaused - Was the game paused via code or a visibility change?
* @private
* @default
*/
this._codePaused = false;

Expand Down
8 changes: 4 additions & 4 deletions src/gameobjects/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ Phaser.Sprite.prototype.preUpdate = function() {
}

// Update any Children
for (var i = 0, len = this.children.length; i < len; i++)
{
this.children[i].preUpdate();
}
// for (var i = 0, len = this.children.length; i < len; i++)
// {
// this.children[i].preUpdate();
// }

return true;

Expand Down
6 changes: 3 additions & 3 deletions src/input/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ Phaser.Keyboard.prototype = {
*/
stop: function () {

this._onKeyDown = null;
this._onKeyUp = null;

window.removeEventListener('keydown', this._onKeyDown);
window.removeEventListener('keyup', this._onKeyUp);

this._onKeyDown = null;
this._onKeyUp = null;

},

/**
Expand Down
124 changes: 97 additions & 27 deletions src/physics/p2/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ Phaser.Physics.P2 = function (game, config) {
this.bounds = null;

/**
* @property {array} _wallShapes - The wall bounds shapes.
* @private
* @property {object} walls - An object containing the 4 wall bodies that bound the physics world.
*/
this._wallShapes = [ null, null, null, null ];
this.walls = { left: null, right: null, top: null, bottom: null };

/**
* @property {Phaser.Signal} onBodyAdded - Dispatched when a new Body is added to the World.
Expand Down Expand Up @@ -474,24 +473,24 @@ Phaser.Physics.P2.prototype = {
if (typeof top === 'undefined') { top = true; }
if (typeof bottom === 'undefined') { bottom = true; }

if (left && this._wallShapes[0])
if (left && this.walls.left)
{
this._wallShapes[0].material = material;
this.walls.left.material = material;
}

if (right && this._wallShapes[1])
if (right && this.walls.right)
{
this._wallShapes[1].material = material;
this.walls.right.material = material;
}

if (top && this._wallShapes[2])
if (top && this.walls.top)
{
this._wallShapes[2].material = material;
this.walls.top.material = material;
}

if (bottom && this._wallShapes[3])
if (bottom && this.walls.bottom)
{
this._wallShapes[3].material = material;
this.walls.bottom.material = material;
}

},
Expand All @@ -506,21 +505,28 @@ Phaser.Physics.P2.prototype = {
*/
updateBoundsCollisionGroup: function (setCollisionGroup) {

if (typeof setCollisionGroup === 'undefined') { setCollisionGroup = true; }
var mask = this.everythingCollisionGroup.mask;

for (var i = 0; i < 4; i++)
if (typeof setCollisionGroup === 'undefined') { mask = this.boundsCollisionGroup.mask; }

if (this.walls.left)
{
if (this._wallShapes[i])
{
if (setCollisionGroup)
{
this._wallShapes[i].collisionGroup = this.boundsCollisionGroup.mask;
}
else
{
this._wallShapes[i].collisionGroup = this.everythingCollisionGroup.mask;
}
}
this.walls.left.collisionGroup = mask;
}

if (this.walls.right)
{
this.walls.right.collisionGroup = mask;
}

if (this.walls.top)
{
this.walls.top.collisionGroup = mask;
}

if (this.walls.bottom)
{
this.walls.bottom.collisionGroup = mask;
}

},
Expand Down Expand Up @@ -553,6 +559,7 @@ Phaser.Physics.P2.prototype = {
var cx = hw + x;
var cy = hh + y;

/*
if (this.bounds !== null)
{
if (this.bounds.world)
Expand All @@ -575,19 +582,81 @@ Phaser.Physics.P2.prototype = {
{
this.bounds = new p2.Body({ mass: 0, position: [this.pxmi(cx), this.pxmi(cy)] });
}
*/

if (this.walls.left)
{
this.world.removeBody(this.walls.left);
}

if (this.walls.right)
{
this.world.removeBody(this.walls.right);
}

if (this.walls.top)
{
this.world.removeBody(this.walls.top);
}

if (this.walls.bottom)
{
this.world.removeBody(this.walls.bottom);
}

if (left)
{
this._wallShapes[0] = new p2.Plane();
this.walls.left = new p2.Body({ mass: 0, position: [ this.pxmi(-hw), this.pxmi(0) ] });
this.walls.left.addShape(new p2.Plane(), 1.5707963267948966);

if (setCollisionGroup)
{
this.walls.left.collisionGroup = this.boundsCollisionGroup.mask;
}

this.world.addBody(this.walls.left);
}

if (right)
{
this.walls.right = new p2.Body({ mass: 0, position: [ this.pxmi(hw), this.pxmi(0) ] });
this.walls.right.addShape(new p2.Plane(), -1.5707963267948966);

if (setCollisionGroup)
{
this.walls.right.collisionGroup = this.boundsCollisionGroup.mask;
}

this.world.addBody(this.walls.right);
}

if (top)
{
this.walls.top = new p2.Body({ mass: 0, position: [ this.pxmi(0), this.pxmi(-hh) ] });
this.walls.top.addShape(new p2.Plane(), -3.141592653589793);

if (setCollisionGroup)
{
this.walls.top.collisionGroup = this.boundsCollisionGroup.mask;
}

this.world.addBody(this.walls.top);
}

if (bottom)
{
this.walls.bottom = new p2.Body({ mass: 0, position: [ this.pxmi(0), this.pxmi(hh) ] });
this.walls.bottom.addShape(new p2.Plane());

if (setCollisionGroup)
{
this._wallShapes[0].collisionGroup = this.boundsCollisionGroup.mask;
this.walls.bottom.collisionGroup = this.boundsCollisionGroup.mask;
}

this.bounds.addShape(this._wallShapes[0], [this.pxmi(-hw), 0], 1.5707963267948966);
this.world.addBody(this.walls.bottom);
}

/*
if (right)
{
this._wallShapes[1] = new p2.Plane();
Expand Down Expand Up @@ -625,6 +694,7 @@ Phaser.Physics.P2.prototype = {
}
this.world.addBody(this.bounds);
*/

},

Expand Down

0 comments on commit 01eec6c

Please sign in to comment.