Skip to content

Commit 49bcd2e

Browse files
committed
Tilemap fixes.
1 parent e1c98ba commit 49bcd2e

10 files changed

Lines changed: 1276 additions & 961 deletions

File tree

build/custom/p2.js

Lines changed: 115 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11595,14 +11595,14 @@ Phaser.Physics.P2.prototype = {
1159511595
* @method Phaser.Physics.P2#createPrismaticConstraint
1159611596
* @param {Phaser.Sprite|Phaser.Physics.P2.Body|p2.Body} bodyA - First connected body.
1159711597
* @param {Phaser.Sprite|Phaser.Physics.P2.Body|p2.Body} bodyB - Second connected body.
11598-
* @param {boolean} [lock=false] - If set to true, bodyB will be free to rotate around its anchor point.
11598+
* @param {boolean} [lockRotation=true] - If set to false, bodyB will be free to rotate around its anchor point.
1159911599
* @param {Array} [anchorA] - Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
1160011600
* @param {Array} [anchorB] - Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
1160111601
* @param {Array} [axis] - An axis, defined in body A frame, that body B's anchor point may slide along. The value is an array with 2 elements matching x and y, i.e: [32, 32].
1160211602
* @param {number} [maxForce] - The maximum force that should be applied to constrain the bodies.
1160311603
* @return {Phaser.Physics.P2.PrismaticConstraint} The constraint
1160411604
*/
11605-
createPrismaticConstraint: function (bodyA, bodyB, lock, anchorA, anchorB, axis, maxForce) {
11605+
createPrismaticConstraint: function (bodyA, bodyB, lockRotation, anchorA, anchorB, axis, maxForce) {
1160611606

1160711607
bodyA = this.getBody(bodyA);
1160811608
bodyB = this.getBody(bodyB);
@@ -11613,7 +11613,7 @@ Phaser.Physics.P2.prototype = {
1161311613
}
1161411614
else
1161511615
{
11616-
return this.addConstraint(new Phaser.Physics.P2.PrismaticConstraint(this, bodyA, bodyB, lock, anchorA, anchorB, axis, maxForce));
11616+
return this.addConstraint(new Phaser.Physics.P2.PrismaticConstraint(this, bodyA, bodyB, lockRotation, anchorA, anchorB, axis, maxForce));
1161711617
}
1161811618

1161911619
},
@@ -13731,6 +13731,108 @@ Phaser.Physics.P2.Body.prototype = {
1373113731

1373213732
},
1373313733

13734+
/**
13735+
* Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.
13736+
* The shape data format is based on the custom phaser export in.
13737+
*
13738+
* @method Phaser.Physics.P2.Body#loadPhaserPolygon
13739+
* @param {string} key - The key of the Physics Data file as stored in Game.Cache.
13740+
* @param {string} object - The key of the object within the Physics data file that you wish to load the shape data from.
13741+
*/
13742+
addPhaserPolygon: function (key, object) {
13743+
13744+
var data = this.game.cache.getPhysicsData(key, object);
13745+
var createdFixtures = [];
13746+
13747+
// Cycle through the fixtures
13748+
for (var i = 0; i < data.length; i++)
13749+
{
13750+
var fixtureData = data[i];
13751+
var shapesOfFixture = this.addFixture(fixtureData);
13752+
createdFixtures[fixtureData.filter.group] = createdFixtures[fixtureData.filter.group] || [];
13753+
createdFixtures[fixtureData.filter.group].push(shapesOfFixture);
13754+
}
13755+
13756+
this.data.aabbNeedsUpdate = true;
13757+
this.shapeChanged();
13758+
13759+
return createdFixtures;
13760+
13761+
},
13762+
13763+
/**
13764+
* Add a polygon fixture. This is used during #loadPhaserPolygon.
13765+
*
13766+
* @method Phaser.Physics.P2.Body#addPolygonFixture
13767+
* @param {string} fixtureData - The data for the fixture. It contains: isSensor, filter (collision) and the actual polygon shapes.
13768+
*/
13769+
addFixture: function (fixtureData) {
13770+
13771+
var generatedShapes = [];
13772+
13773+
if (fixtureData.circle)
13774+
{
13775+
var shape = new p2.Circle(this.world.pxm(fixtureData.circle.radius))
13776+
shape.collisionGroup = fixtureData.filter.categoryBits
13777+
shape.collisionMask = fixtureData.filter.maskBits
13778+
shape.sensor = fixtureData.isSensor
13779+
13780+
var offset = p2.vec2.create();
13781+
offset[0] = this.world.pxmi(fixtureData.circle.position[0] - this.sprite.width/2)
13782+
offset[1] = this.world.pxmi(fixtureData.circle.position[1] - this.sprite.height/2)
13783+
13784+
this.data.addShape(shape, offset);
13785+
generatedShapes.push(shape)
13786+
}
13787+
else
13788+
{
13789+
polygons = fixtureData.polygons;
13790+
13791+
var cm = p2.vec2.create();
13792+
13793+
for (var i = 0; i < polygons.length; i++)
13794+
{
13795+
shapes = polygons[i];
13796+
13797+
var vertices = [];
13798+
13799+
for (var s = 0; s < shapes.length; s += 2)
13800+
{
13801+
vertices.push([ this.world.pxmi(shapes[s]), this.world.pxmi(shapes[s + 1]) ]);
13802+
}
13803+
13804+
var shape = new p2.Convex(vertices);
13805+
13806+
// Move all vertices so its center of mass is in the local center of the convex
13807+
for (var j = 0; j !== shape.vertices.length; j++)
13808+
{
13809+
var v = shape.vertices[j];
13810+
p2.vec2.sub(v, v, shape.centerOfMass);
13811+
}
13812+
13813+
p2.vec2.scale(cm, shape.centerOfMass, 1);
13814+
13815+
cm[0] -= this.world.pxmi(this.sprite.width / 2);
13816+
cm[1] -= this.world.pxmi(this.sprite.height / 2);
13817+
13818+
shape.updateTriangles();
13819+
shape.updateCenterOfMass();
13820+
shape.updateBoundingRadius();
13821+
13822+
shape.collisionGroup = fixtureData.filter.categoryBits;
13823+
shape.collisionMask = fixtureData.filter.maskBits;
13824+
shape.sensor = fixtureData.isSensor;
13825+
13826+
this.data.addShape(shape, cm);
13827+
13828+
generatedShapes.push(shape);
13829+
}
13830+
}
13831+
13832+
return generatedShapes;
13833+
13834+
},
13835+
1373413836
/**
1373513837
* Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.
1373613838
*
@@ -13750,12 +13852,12 @@ Phaser.Physics.P2.Body.prototype = {
1375013852
if (data.length === 1)
1375113853
{
1375213854
var temp = [];
13855+
var localData = data[data.length - 1];
1375313856

13754-
data = data.pop()
1375513857
// We've a list of numbers
13756-
for (var i = 0, len = data.shape.length; i < len; i += 2)
13858+
for (var i = 0, len = localData.shape.length; i < len; i += 2)
1375713859
{
13758-
temp.push([data.shape[i], data.shape[i + 1]]);
13860+
temp.push([localData.shape[i], localData.shape[i + 1]]);
1375913861
}
1376013862

1376113863
return this.addPolygon(options, temp);
@@ -14454,7 +14556,7 @@ Phaser.Utils.extend(Phaser.Physics.P2.BodyDebug.prototype, {
1445414556

1445514557
if (child instanceof p2.Circle)
1445614558
{
14457-
this.drawCircle(sprite, offset[0] * this.ppu, -offset[1] * this.ppu, angle, child.radius * this.ppu, color, lw);
14559+
this.drawCircle(sprite, offset[0] * this.ppu, offset[1] * this.ppu, angle, child.radius * this.ppu, color, lw);
1445814560
}
1445914561
else if (child instanceof p2.Convex)
1446014562
{
@@ -15092,15 +15194,15 @@ Phaser.Physics.P2.LockConstraint.prototype.constructor = Phaser.Physics.P2.LockC
1509215194
* @param {Phaser.Physics.P2} world - A reference to the P2 World.
1509315195
* @param {p2.Body} bodyA - First connected body.
1509415196
* @param {p2.Body} bodyB - Second connected body.
15095-
* @param {boolean} [lock=false] - If set to true, bodyB will be free to rotate around its anchor point.
15197+
* @param {boolean} [lockRotation=true] - If set to false, bodyB will be free to rotate around its anchor point.
1509615198
* @param {Array} [anchorA] - Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
1509715199
* @param {Array} [anchorB] - Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
1509815200
* @param {Array} [axis] - An axis, defined in body A frame, that body B's anchor point may slide along. The value is an array with 2 elements matching x and y, i.e: [32, 32].
1509915201
* @param {number} [maxForce] - The maximum force that should be applied to constrain the bodies.
1510015202
*/
15101-
Phaser.Physics.P2.PrismaticConstraint = function (world, bodyA, bodyB, lock, anchorA, anchorB, axis, maxForce) {
15203+
Phaser.Physics.P2.PrismaticConstraint = function (world, bodyA, bodyB, lockRotation, anchorA, anchorB, axis, maxForce) {
1510215204

15103-
if (typeof lock === 'undefined') { lock = false; }
15205+
if (typeof lockRotation === 'undefined') { lockRotation = true; }
1510415206
if (typeof anchorA === 'undefined') { anchorA = [0, 0]; }
1510515207
if (typeof anchorB === 'undefined') { anchorB = [0, 0]; }
1510615208
if (typeof axis === 'undefined') { axis = [0, 0]; }
@@ -15119,7 +15221,7 @@ Phaser.Physics.P2.PrismaticConstraint = function (world, bodyA, bodyB, lock, anc
1511915221
anchorA = [ world.pxmi(anchorA[0]), world.pxmi(anchorA[1]) ];
1512015222
anchorB = [ world.pxmi(anchorB[0]), world.pxmi(anchorB[1]) ];
1512115223

15122-
var options = { localAnchorA: anchorA, localAnchorB: anchorB, localAxisA: axis, maxForce: maxForce, disableRotationalLock: lock };
15224+
var options = { localAnchorA: anchorA, localAnchorB: anchorB, localAxisA: axis, maxForce: maxForce, disableRotationalLock: !lockRotation };
1512315225

1512415226
p2.PrismaticConstraint.call(this, bodyA, bodyB, options);
1512515227

@@ -15162,8 +15264,8 @@ Phaser.Physics.P2.RevoluteConstraint = function (world, bodyA, pivotA, bodyB, pi
1516215264
*/
1516315265
this.world = world;
1516415266

15165-
pivotA = [ world.pxm(pivotA[0]), world.pxm(pivotA[1]) ];
15166-
pivotB = [ world.pxm(pivotB[0]), world.pxm(pivotB[1]) ];
15267+
pivotA = [ world.pxmi(pivotA[0]), world.pxmi(pivotA[1]) ];
15268+
pivotB = [ world.pxmi(pivotB[0]), world.pxmi(pivotB[1]) ];
1516715269

1516815270
p2.RevoluteConstraint.call(this, bodyA, pivotA, bodyB, pivotB, maxForce);
1516915271

build/custom/p2.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)