Skip to content

Commit a4982fa

Browse files
committed
better fixture handling
1 parent 277afa1 commit a4982fa

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

exporter/PhysicsEditor/phaser.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{
66
"isSensor": {{fixture.isSensor}},
77
"filter": {
8+
"group": {{fixture.filter_groupIndex}},
89
"categoryBits": {{fixture.filter_categoryBits}},
910
"maskBits": {{fixture.filter_maskBits}}
1011
},

src/physics/p2/Body.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,24 +1097,27 @@ Phaser.Physics.P2.Body.prototype = {
10971097

10981098
/**
10991099
* Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.
1100-
* The shape data format is based on the custom phaser export in PhysicsEditor
1100+
* The shape data format is based on the custom phaser export in
11011101
* @method Phaser.Physics.P2.Body#loadPhaserPolygon
11021102
* @param {string} key - The key of the Physics Data file as stored in Game.Cache.
11031103
* @param {string} object - The key of the object within the Physics data file that you wish to load the shape data from.
11041104
*/
1105-
loadPhaserPolygon: function (key, object) {
1105+
addPhaserPolygon: function (key, object) {
11061106
var data = this.game.cache.getPhysicsData(key, object);
1107+
var createdFixtures = []
11071108
//cycle through the fixtures
11081109
for (var i = 0; i < data.length; i++)
11091110
{
11101111
var fixtureData = data[i]
1111-
this.addFixture(fixtureData)
1112+
var shapesOfFixture = this.addFixture(fixtureData)
1113+
createdFixtures[fixtureData.filter.group] = createdFixtures[fixtureData.filter.group] || []
1114+
createdFixtures[fixtureData.filter.group].push(shapesOfFixture)
11121115
}
11131116

11141117
this.data.aabbNeedsUpdate = true;
11151118
this.shapeChanged();
11161119

1117-
return false;
1120+
return createdFixtures;
11181121

11191122
},
11201123

@@ -1127,7 +1130,8 @@ Phaser.Physics.P2.Body.prototype = {
11271130
*/
11281131

11291132
addFixture: function(fixtureData){
1130-
console.log('addPolygonFixture', fixtureData)
1133+
//console.log('addPolygonFixture', fixtureData)
1134+
var generatedShapes = []
11311135

11321136
if (fixtureData.circle){
11331137
//a circle has unfortunately no position in p2. pretty useless.
@@ -1137,6 +1141,7 @@ Phaser.Physics.P2.Body.prototype = {
11371141
shape.sensor = fixtureData.isSensor
11381142

11391143
this.data.addShape(shape);
1144+
generatedShapes.push(shape)
11401145
}else{
11411146
polygons = fixtureData.polygons
11421147
var cm = p2.vec2.create();
@@ -1174,9 +1179,12 @@ Phaser.Physics.P2.Body.prototype = {
11741179
shape.sensor = fixtureData.isSensor
11751180

11761181
this.data.addShape(shape, cm);
1182+
1183+
generatedShapes.push(shape)
11771184
}
11781185
}
11791186

1187+
return generatedShapes
11801188

11811189
},
11821190

0 commit comments

Comments
 (0)