Skip to content

Commit ac4acfb

Browse files
committed
Removed Arcade Physics Circle support (now in its own branch) ready for 2.4.7 release.
1 parent 4d8753e commit ac4acfb

2 files changed

Lines changed: 22 additions & 218 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,6 @@ Phaser.Physics.Arcade.Body = function (sprite) {
3535
*/
3636
this.enable = true;
3737

38-
/**
39-
* If `true` this Body is using circular collision detection. If `false` it is using rectangular.
40-
* Use `Body.setCircle` to control the collision shape this Body uses.
41-
* @property {boolean} isCircle
42-
* @default
43-
* @readOnly
44-
*/
45-
this.isCircle = false;
46-
47-
/**
48-
* The radius of the circular collision shape this Body is using if Body.setCircle has been enabled.
49-
* If you wish to change the radius then call `setCircle` again with the new value.
50-
* If you wish to stop the Body using a circle then call `setCircle` with a radius of zero (or undefined).
51-
* @property {float} radius
52-
* @default
53-
* @readOnly
54-
*/
55-
this.radius = 0;
56-
5738
/**
5839
* @property {Phaser.Point} offset - The offset of the Physics Body from the Sprite x/y position.
5940
*/
@@ -282,12 +263,6 @@ Phaser.Physics.Arcade.Body = function (sprite) {
282263
*/
283264
this.overlapY = 0;
284265

285-
/**
286-
* If `Body.isCircle` is true, and this body collides with another circular body, the amount of overlap is stored here.
287-
* @property {number} overlapR - The amount of overlap during the collision.
288-
*/
289-
this.overlapR = 0;
290-
291266
/**
292267
* If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true.
293268
* @property {boolean} embedded - Body embed value.
@@ -986,43 +961,15 @@ Phaser.Physics.Arcade.Body.render = function (context, body, color, filled) {
986961

987962
color = color || 'rgba(0,255,0,0.4)';
988963

989-
if (body.isCircle)
964+
if (filled)
990965
{
991-
context.save();
992-
context.setTransform(1, 0, 0, 1, 0, 0);
993-
994-
context.beginPath();
995-
context.arc(body.center.x - body.game.camera.x, body.center.y - body.game.camera.y, body.radius, 0, 2 * Math.PI);
996-
context.closePath();
997-
998-
if (filled)
999-
{
1000-
context.fillStyle = color;
1001-
context.fill();
1002-
}
1003-
else
1004-
{
1005-
context.strokeStyle = color;
1006-
context.stroke();
1007-
}
1008-
1009-
// context.strokeStyle = '#ffff00';
1010-
// context.strokeRect(body.position.x - body.game.camera.x, body.position.y - body.game.camera.y, body.width, body.height);
1011-
1012-
context.restore();
966+
context.fillStyle = color;
967+
context.fillRect(body.position.x - body.game.camera.x, body.position.y - body.game.camera.y, body.width, body.height);
1013968
}
1014969
else
1015970
{
1016-
if (filled)
1017-
{
1018-
context.fillStyle = color;
1019-
context.fillRect(body.position.x - body.game.camera.x, body.position.y - body.game.camera.y, body.width, body.height);
1020-
}
1021-
else
1022-
{
1023-
context.strokeStyle = color;
1024-
context.strokeRect(body.position.x - body.game.camera.x, body.position.y - body.game.camera.y, body.width, body.height);
1025-
}
971+
context.strokeStyle = color;
972+
context.strokeRect(body.position.x - body.game.camera.x, body.position.y - body.game.camera.y, body.width, body.height);
1026973
}
1027974

1028975
};

src/physics/arcade/World.js

Lines changed: 17 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ Phaser.Physics.Arcade = function (game) {
8282
*/
8383
this._total = 0;
8484

85-
this._pos1 = { x: 0, y: 0 };
86-
this._pos2 = { x: 0, y: 0 };
87-
88-
this._vel1 = { x: 0, y: 0 };
89-
this._vel2 = { x: 0, y: 0 };
90-
91-
this._velF = { x1: 0, y1: 0, x2: 0, y2: 0 };
92-
9385
// By default we want the bounds the same size as the world bounds
9486
this.setBoundsToWorld();
9587

@@ -955,12 +947,6 @@ Phaser.Physics.Arcade.prototype = {
955947
return false;
956948
}
957949

958-
// Circle vs. Circle quick bail out
959-
if (body1.isCircle && body2.isCircle)
960-
{
961-
return this.separateCircle(body1, body2, overlapOnly);
962-
}
963-
964950
var resultX = false;
965951
var resultY = false;
966952

@@ -994,8 +980,8 @@ Phaser.Physics.Arcade.prototype = {
994980
* Check for intersection against two bodies.
995981
*
996982
* @method Phaser.Physics.Arcade#intersects
997-
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body object to check.
998-
* @param {Phaser.Physics.Arcade.Body} body2 - The second Body object to check.
983+
* @param {Phaser.Physics.Arcade.Body} body1 - The Body object to check.
984+
* @param {Phaser.Physics.Arcade.Body} body2 - The Body object to check.
999985
* @return {boolean} True if they intersect, otherwise false.
1000986
*/
1001987
intersects: function (body1, body2) {
@@ -1050,152 +1036,14 @@ Phaser.Physics.Arcade.prototype = {
10501036
},
10511037

10521038
/**
1053-
* Checks to see if a circular Body intersects with a Rectangular Body.
1054-
*
1055-
* @method Phaser.Physics.Arcade#circleBodyIntersects
1056-
* @param {Phaser.Physics.Arcade.Body} circle - The Body with `isCircle` set.
1057-
* @param {Phaser.Physics.Arcade.Body} body - The Body with `isCircle` not set (i.e. uses Rectangle shape)
1058-
* @return {boolean} Returns true if the bodies intersect, otherwise false.
1059-
*/
1060-
circleBodyIntersects: function (circle, body) {
1061-
1062-
var x = Phaser.Math.clamp(circle.center.x, body.left, body.right);
1063-
var y = Phaser.Math.clamp(circle.center.y, body.top, body.bottom);
1064-
1065-
var dx = (circle.center.x - x) * (circle.center.x - x);
1066-
var dy = (circle.center.y - y) * (circle.center.y - y);
1067-
1068-
return (dx + dy) <= (circle.radius * circle.radius);
1069-
1070-
},
1071-
1072-
/**
1073-
* The core separation function to separate two circular physics bodies.
1074-
*
1075-
* @method Phaser.Physics.Arcade#separateCircle
1076-
* @private
1077-
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate. Must have `Body.isCircle` true and a positive `radius`.
1078-
* @param {Phaser.Physics.Arcade.Body} body2 - The second Body to separate. Must have `Body.isCircle` true and a positive `radius`.
1079-
* @param {boolean} overlapOnly - If true the bodies will only have their overlap data set, no separation or exchange of velocity will take place.
1080-
* @return {boolean} Returns true if the bodies were separated or overlap, otherwise false.
1081-
*/
1082-
separateCircle: function (body1, body2, overlapOnly) {
1083-
1084-
// Set the bounding box overlap values
1085-
this.getOverlapX(body1, body2);
1086-
this.getOverlapY(body1, body2);
1087-
1088-
var dx = body2.center.x - body1.center.x;
1089-
var dy = body2.center.y - body1.center.y;
1090-
1091-
var angle = Math.atan2(dy, dx);
1092-
var sin = Math.sin(angle);
1093-
var cos = Math.cos(angle);
1094-
1095-
this._pos1.x = 0;
1096-
this._pos1.y = 0;
1097-
1098-
// Rotate the second body to the angle of the first
1099-
this.rotate(this._pos2, dx, dy, sin, cos, true);
1100-
1101-
// Rotate the velocities
1102-
this.rotate(this._vel1, body1.velocity.x, body1.velocity.y, sin, cos, true);
1103-
this.rotate(this._vel2, body2.velocity.x, body2.velocity.y, sin, cos, true);
1104-
1105-
// Calculate overlap
1106-
if (body1.mass === body2.mass)
1107-
{
1108-
// Swap 'em
1109-
var tempX = this._vel1.x;
1110-
var tempY = this._vel1.y;
1111-
1112-
this._vel1.x = this._vel2.x;
1113-
this._vel1.y = this._vel2.y;
1114-
1115-
this._vel2.x = tempX;
1116-
this._vel2.y = tempY;
1117-
}
1118-
else
1119-
{
1120-
// Mass based exchange
1121-
var vxTotal = this._vel1.x - this._vel2.x;
1122-
1123-
this._vel1.x = ((body1.mass - body2.mass) * this._vel1.x + 2 * body2.mass * this._vel2.x) / (body1.mass + body2.mass);
1124-
this._vel2.x = vxTotal + this._vel1.x;
1125-
}
1126-
1127-
var overlap = (body1.radius + body2.radius) - Phaser.Math.distance(body1.center.x, body1.center.y, body2.center.x, body2.center.y);
1128-
1129-
// Resets the overlapR to zero if there is no overlap, or to the actual pixel value if there is
1130-
body1.overlapR = overlap * 0.5;
1131-
body2.overlapR = overlap * 0.5;
1132-
1133-
// Can't separate two immovable bodies, or a body with its own custom separation logic
1134-
if (overlapOnly || overlap === 0 || (body1.immovable && body2.immovable) || body1.customSeparateX || body2.customSeparateX)
1135-
{
1136-
// return true if there was some overlap, otherwise false
1137-
return (overlap !== 0);
1138-
}
1139-
1140-
this._pos1.x += (this._vel1.x * this.game.time.physicsElapsed) + overlap;
1141-
this._pos2.x += (this._vel2.x * this.game.time.physicsElapsed) + overlap;
1142-
1143-
// Rotate positions back again
1144-
this.rotate(this._pos1, this._pos1.x, this._pos1.y, sin, cos, false);
1145-
this.rotate(this._pos2, this._pos2.x, this._pos2.y, sin, cos, false);
1146-
1147-
// Rotate velocity back again
1148-
this.rotate(this._vel1, this._vel1.x, this._vel1.y, sin, cos, false);
1149-
this.rotate(this._vel2, this._vel2.x, this._vel2.y, sin, cos, false);
1150-
1151-
// Apply to bodies
1152-
1153-
body2.x = body1.x + this._pos2.x;
1154-
body2.y = body1.y + this._pos2.y;
1155-
1156-
body1.x = body1.x + this._pos1.x;
1157-
body1.y = body1.y + this._pos1.y;
1158-
1159-
body1.velocity.x = this._vel1.x;
1160-
body1.velocity.y = this._vel1.y;
1161-
1162-
body2.velocity.x = this._vel2.x;
1163-
body2.velocity.y = this._vel2.y;
1164-
1165-
return true;
1166-
1167-
},
1168-
1169-
/**
1170-
* Point rotation method, used by circle separation.
1039+
* Calculates the horizontal overlap between two Bodies and sets their properties accordingly, including:
1040+
* `touching.left`, `touching.right` and `overlapX`.
11711041
*
1172-
* @method Phaser.Physics.Arcade#rotate
1173-
* @private
1174-
* @param {Object|Phaser.Point} result - The Point-like object in which to store the calculation results.
1175-
* @param {float} x - The x component.
1176-
* @param {float} y - The y component.
1177-
* @param {float} sin - The sin of the rotation.
1178-
* @param {float} cos - The cos of the rotation.
1179-
* @param {boolean} reverse - True to rotate back, false to rotate forward.
1180-
* @return {Object|Phaser.Point} The result object.
1042+
* @method Phaser.Physics.Arcade#getOverlapX
1043+
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate.
1044+
* @param {Phaser.Physics.Arcade.Body} body2 - The second Body to separate.
1045+
* @return {float} Returns the amount of horizontal overlap between the two bodies.
11811046
*/
1182-
rotate: function (result, x, y, sin, cos, reverse) {
1183-
1184-
if (reverse)
1185-
{
1186-
result.x = x * cos + y * sin;
1187-
result.y = y * cos - x * sin;
1188-
}
1189-
else
1190-
{
1191-
result.x = x * cos - y * sin;
1192-
result.y = y * cos + x * sin;
1193-
}
1194-
1195-
return result;
1196-
1197-
},
1198-
11991047
getOverlapX: function (body1, body2) {
12001048

12011049
var overlap = 0;
@@ -1250,6 +1098,15 @@ Phaser.Physics.Arcade.prototype = {
12501098

12511099
},
12521100

1101+
/**
1102+
* Calculates the vertical overlap between two Bodies and sets their properties accordingly, including:
1103+
* `touching.up`, `touching.down` and `overlapY`.
1104+
*
1105+
* @method Phaser.Physics.Arcade#getOverlapY
1106+
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate.
1107+
* @param {Phaser.Physics.Arcade.Body} body2 - The second Body to separate.
1108+
* @return {float} Returns the amount of vertical overlap between the two bodies.
1109+
*/
12531110
getOverlapY: function (body1, body2) {
12541111

12551112
var overlap = 0;

0 commit comments

Comments
 (0)