Skip to content

Commit 956fa49

Browse files
committed
The P2.Body.onBeginContact arguments have changed. It now sends 5 arguments: The Phaser.P2.Body, the p2.Body, the p2 Shape from Body A, the p2 Shape from Body B and the contact equations array. Note that the Phaser.P2.Body may be null if you collide with a 'native' p2 body (such as the world bounds). However the p2.Body argument will always be populated.
The P2.Body.onEndContact arguments have changed. It now sends 4 arguments: The Phaser.P2.Body, the p2.Body, the p2 Shape from Body A and the p2 Shape from Body B. Note that the Phaser.P2.Body may be null if this is the end of a contact with a 'native' p2 body (such as the world bounds). However the p2.Body argument will always be populated. Upgraded to p2.js 0.7.0
1 parent 502dd54 commit 956fa49

4 files changed

Lines changed: 2311 additions & 2939 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ Version 2.4 - "Katar" - in dev
245245
* Phaser.BitmapText no longer extends PIXI.BitmapText but replaces it entirely.
246246
* Phaser.Text no longer extends PIXI.Text but replaces it entirely. Phaser.Text now natively extends a Phaser Sprite, meaning it can be enabled for physics, damaged, etc.
247247
* Mouse.button and MSPointer.button have been removed. They never supported complex button events (such as holding down 2 buttons and releasing just one) or any buttons other than left and right. They have been replaced with the far more robust and accurate Pointer button properties such as `Pointer.leftButton`, `Pointer.rightButton` and so on.
248+
* The P2.Body.onBeginContact arguments have changed. It now sends 5 arguments: The Phaser.P2.Body, the p2.Body, the p2 Shape from Body A, the p2 Shape from Body B and the contact equations array. Note that the Phaser.P2.Body may be null if you collide with a 'native' p2 body (such as the world bounds). However the p2.Body argument will always be populated.
249+
* The P2.Body.onEndContact arguments have changed. It now sends 4 arguments: The Phaser.P2.Body, the p2.Body, the p2 Shape from Body A and the p2 Shape from Body B. Note that the Phaser.P2.Body may be null if this is the end of a contact with a 'native' p2 body (such as the world bounds). However the p2.Body argument will always be populated.
250+
251+
### p2.js Upgraded to version 0.7
248252

249253
### New Features
250254

@@ -513,7 +517,7 @@ The Phaser logo and characters are © 2015 Photon Storm Limited.
513517

514518
All rights reserved.
515519

516-
"The art challenges the technology, and the technology inspires the art." - John Lasseter
520+
"Above all, video games are meant to be just one thing: fun. Fun for everyone." - Satoru Iwata
517521

518522
[![Analytics](https://ga-beacon.appspot.com/UA-44006568-2/phaser/index)](https://github.com/igrigorik/ga-beacon)
519523

src/physics/p2/Body.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,32 @@ Phaser.Physics.P2.Body = function (game, sprite, x, y, mass) {
7676
this.gravity = new Phaser.Point();
7777

7878
/**
79-
* Dispatched when a first contact is created between shapes in two bodies. This event is fired during the step, so collision has already taken place.
80-
* The event will be sent 4 parameters: The body it is in contact with, the shape from this body that caused the contact, the shape from the contact body and the contact equation data array.
79+
* Dispatched when a first contact is created between shapes in two bodies.
80+
* This event is fired during the step, so collision has already taken place.
81+
*
82+
* The event will be sent 5 arguments in this order:
83+
*
84+
* The Phaser.Physics.P2.Body it is in contact with. *This might be null* if the Body was created directly in the p2 world.
85+
* The p2.Body this Body is in contact with.
86+
* The Shape from this body that caused the contact.
87+
* The Shape from the contact body.
88+
* The Contact Equation data array.
89+
*
8190
* @property {Phaser.Signal} onBeginContact
8291
*/
8392
this.onBeginContact = new Phaser.Signal();
8493

8594
/**
86-
* Dispatched when contact ends between shapes in two bodies. This event is fired during the step, so collision has already taken place.
87-
* The event will be sent 3 parameters: The body it is in contact with, the shape from this body that caused the contact and the shape from the contact body.
95+
* Dispatched when contact ends between shapes in two bodies.
96+
* This event is fired during the step, so collision has already taken place.
97+
*
98+
* The event will be sent 4 arguments in this order:
99+
*
100+
* The Phaser.Physics.P2.Body it is in contact with. *This might be null* if the Body was created directly in the p2 world.
101+
* The p2.Body this Body has ended contact with.
102+
* The Shape from this body that caused the original contact.
103+
* The Shape from the contact body.
104+
*
88105
* @property {Phaser.Signal} onEndContact
89106
*/
90107
this.onEndContact = new Phaser.Signal();
@@ -861,7 +878,7 @@ Phaser.Physics.P2.Body.prototype = {
861878
*/
862879
addCircle: function (radius, offsetX, offsetY, rotation) {
863880

864-
var shape = new p2.Circle(this.world.pxm(radius));
881+
var shape = new p2.Circle({ radius: this.world.pxm(radius) });
865882

866883
return this.addShape(shape, offsetX, offsetY, rotation);
867884

@@ -876,11 +893,11 @@ Phaser.Physics.P2.Body.prototype = {
876893
* @param {number} [offsetX=0] - Local horizontal offset of the shape relative to the body center of mass.
877894
* @param {number} [offsetY=0] - Local vertical offset of the shape relative to the body center of mass.
878895
* @param {number} [rotation=0] - Local rotation of the shape relative to the body center of mass, specified in radians.
879-
* @return {p2.Rectangle} The Rectangle shape that was added to the Body.
896+
* @return {p2.Box} The shape that was added to the Body.
880897
*/
881898
addRectangle: function (width, height, offsetX, offsetY, rotation) {
882899

883-
var shape = new p2.Rectangle(this.world.pxm(width), this.world.pxm(height));
900+
var shape = new p2.Box({ width: this.world.pxm(width), height: this.world.pxm(height)});
884901

885902
return this.addShape(shape, offsetX, offsetY, rotation);
886903

@@ -934,7 +951,7 @@ Phaser.Physics.P2.Body.prototype = {
934951
*/
935952
addLine: function (length, offsetX, offsetY, rotation) {
936953

937-
var shape = new p2.Line(this.world.pxm(length));
954+
var shape = new p2.Line({ length: this.world.pxm(length)});
938955

939956
return this.addShape(shape, offsetX, offsetY, rotation);
940957

@@ -954,7 +971,7 @@ Phaser.Physics.P2.Body.prototype = {
954971
*/
955972
addCapsule: function (length, radius, offsetX, offsetY, rotation) {
956973

957-
var shape = new p2.Capsule(this.world.pxm(length), this.world.pxm(radius));
974+
var shape = new p2.Capsule({ length: this.world.pxm(length), radius: this.world.pxm(radius) });
958975

959976
return this.addShape(shape, offsetX, offsetY, rotation);
960977

@@ -1192,7 +1209,7 @@ Phaser.Physics.P2.Body.prototype = {
11921209

11931210
if (fixtureData.circle)
11941211
{
1195-
var shape = new p2.Circle(this.world.pxm(fixtureData.circle.radius));
1212+
var shape = new p2.Circle({ radius: this.world.pxm(fixtureData.circle.radius) });
11961213
shape.collisionGroup = fixtureData.filter.categoryBits;
11971214
shape.collisionMask = fixtureData.filter.maskBits;
11981215
shape.sensor = fixtureData.isSensor;
@@ -1219,7 +1236,7 @@ Phaser.Physics.P2.Body.prototype = {
12191236
vertices.push([ this.world.pxmi(shapes[s]), this.world.pxmi(shapes[s + 1]) ]);
12201237
}
12211238

1222-
var shape = new p2.Convex(vertices);
1239+
var shape = new p2.Convex({ vertices: vertices });
12231240

12241241
// Move all vertices so its center of mass is in the local center of the convex
12251242
for (var j = 0; j !== shape.vertices.length; j++)
@@ -1289,7 +1306,7 @@ Phaser.Physics.P2.Body.prototype = {
12891306
vertices.push([ this.world.pxmi(data[i].shape[s]), this.world.pxmi(data[i].shape[s + 1]) ]);
12901307
}
12911308

1292-
var c = new p2.Convex(vertices);
1309+
var c = new p2.Convex({ vertices: vertices });
12931310

12941311
// Move all vertices so its center of mass is in the local center of the convex
12951312
for (var j = 0; j !== c.vertices.length; j++)

src/physics/p2/World.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,19 @@ Phaser.Physics.P2.prototype = {
507507
*/
508508
beginContactHandler: function (event) {
509509

510-
this.onBeginContact.dispatch(event.bodyA, event.bodyB, event.shapeA, event.shapeB, event.contactEquations);
511-
512-
if (event.bodyA.parent)
510+
if (event.bodyA && event.bodyB)
513511
{
514-
event.bodyA.parent.onBeginContact.dispatch(event.bodyB.parent, event.shapeA, event.shapeB, event.contactEquations);
515-
}
512+
this.onBeginContact.dispatch(event.bodyA, event.bodyB, event.shapeA, event.shapeB, event.contactEquations);
516513

517-
if (event.bodyB.parent)
518-
{
519-
event.bodyB.parent.onBeginContact.dispatch(event.bodyA.parent, event.shapeB, event.shapeA, event.contactEquations);
514+
if (event.bodyA.parent)
515+
{
516+
event.bodyA.parent.onBeginContact.dispatch(event.bodyB.parent, event.bodyB, event.shapeA, event.shapeB, event.contactEquations);
517+
}
518+
519+
if (event.bodyB.parent)
520+
{
521+
event.bodyB.parent.onBeginContact.dispatch(event.bodyA.parent, event.bodyA, event.shapeB, event.shapeA, event.contactEquations);
522+
}
520523
}
521524

522525
},
@@ -529,16 +532,19 @@ Phaser.Physics.P2.prototype = {
529532
*/
530533
endContactHandler: function (event) {
531534

532-
this.onEndContact.dispatch(event.bodyA, event.bodyB, event.shapeA, event.shapeB);
533-
534-
if (event.bodyA.parent)
535+
if (event.bodyA && event.bodyB)
535536
{
536-
event.bodyA.parent.onEndContact.dispatch(event.bodyB.parent, event.shapeA, event.shapeB);
537-
}
537+
this.onEndContact.dispatch(event.bodyA, event.bodyB, event.shapeA, event.shapeB);
538538

539-
if (event.bodyB.parent)
540-
{
541-
event.bodyB.parent.onEndContact.dispatch(event.bodyA.parent, event.shapeB, event.shapeA);
539+
if (event.bodyA.parent)
540+
{
541+
event.bodyA.parent.onEndContact.dispatch(event.bodyB.parent, event.bodyB, event.shapeA, event.shapeB);
542+
}
543+
544+
if (event.bodyB.parent)
545+
{
546+
event.bodyB.parent.onEndContact.dispatch(event.bodyA.parent, event.bodyA, event.shapeB, event.shapeA);
547+
}
542548
}
543549

544550
},

0 commit comments

Comments
 (0)