Skip to content

Commit 77f8e5e

Browse files
committed
P2 Fixtures Collection Class (@georgiee please test it works ok! phaserjs#704)
1 parent 3a1c202 commit 77f8e5e

4 files changed

Lines changed: 252 additions & 190 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ Updates
8989
* p2.World bounds are now included in the callback events such as beginContact and impact events.
9090
* Thanks to @STuFF the Classes list in the API docs now indents sub-classes.
9191

92+
I created a collection class to easily access the fixtures of a created P2 Body.
93+
This is especially useful in combination with PhysicsEditor and Body#addPhaserPolygon.
94+
95+
You can configure your whole collision grouping in PhysicsEditor and then you can later change the mask bits easily with this class. You bypassed phaser's body wrapper so you cannot (or want to) simply activate the collision groups in phaser.
96+
97+
You can also access parts (groups) and named fixtures by a group index or a fixture key - both properties can be set in PhysicsEditor with the custom phaser exporter.
98+
99+
Use cases:
100+
101+
Configure collision bits in PhysicsEditor and you want to change them later.
102+
Place a sensor in your fixture and access this single fixture later (to disable temporarily)
103+
Create a small body with threes fixtures (circle, circle + polygon/convex). Now you want that the polygon part to behave like rubber and assign a bouncing (restitution > 1) material. Assign a fixture key in PhysicsEditor and access the fixture like this. (see the image for the fixture I described)
104+
105+
92106

93107
New Features
94108

src/physics/p2/Body.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,13 +1112,14 @@ Phaser.Physics.P2.Body.prototype = {
11121112
var fixtureData = data[i];
11131113
var shapesOfFixture = this.addFixture(fixtureData);
11141114

1115-
//always add to a group
1116-
createdFixtures[fixtureData.filter.group] = createdFixtures[fixtureData.filter.group] || []
1117-
createdFixtures[fixtureData.filter.group] = createdFixtures[fixtureData.filter.group].concat(shapesOfFixture)
1115+
// Always add to a group
1116+
createdFixtures[fixtureData.filter.group] = createdFixtures[fixtureData.filter.group] || [];
1117+
createdFixtures[fixtureData.filter.group] = createdFixtures[fixtureData.filter.group].concat(shapesOfFixture);
11181118

1119-
//if (unique) fixture key is provided
1120-
if(fixtureData.fixtureKey){
1121-
createdFixtures[fixtureData.fixtureKey] = shapesOfFixture
1119+
// if (unique) fixture key is provided
1120+
if (fixtureData.fixtureKey)
1121+
{
1122+
createdFixtures[fixtureData.fixtureKey] = shapesOfFixture;
11221123
}
11231124
}
11241125

0 commit comments

Comments
 (0)