|
4 | 4 | * @license {@link https://opensource.org/licenses/MIT|MIT License} |
5 | 5 | */ |
6 | 6 |
|
7 | | -var CircleContains = require('../../geom/circle/Contains'); |
8 | 7 | var Class = require('../../utils/Class'); |
9 | 8 | var CONST = require('./const'); |
10 | 9 | var Events = require('./events'); |
@@ -421,14 +420,14 @@ var Body = new Class({ |
421 | 420 |
|
422 | 421 | /** |
423 | 422 | * The maximum speed this Body is allowed to reach. |
424 | | - * |
| 423 | + * |
425 | 424 | * If not negative it limits the scalar value of speed. |
426 | | - * |
| 425 | + * |
427 | 426 | * Any negative value means no maximum is being applied. |
428 | | - * |
| 427 | + * |
429 | 428 | * @name Phaser.Physics.Arcade.Body#maxSpeed |
430 | 429 | * @type {number} |
431 | | - * @since 3.16.0 |
| 430 | + * @since 3.16.0 |
432 | 431 | */ |
433 | 432 | this.maxSpeed = -1; |
434 | 433 |
|
@@ -844,7 +843,7 @@ var Body = new Class({ |
844 | 843 |
|
845 | 844 | /** |
846 | 845 | * Prepares the Body for a physics step by resetting the `wasTouching`, `touching` and `blocked` states. |
847 | | - * |
| 846 | + * |
848 | 847 | * This method is only called if the physics world is going to run a step this frame. |
849 | 848 | * |
850 | 849 | * @method Phaser.Physics.Arcade.Body#resetFlags |
@@ -880,12 +879,12 @@ var Body = new Class({ |
880 | 879 |
|
881 | 880 | /** |
882 | 881 | * Syncs the position body position with the parent Game Object. |
883 | | - * |
| 882 | + * |
884 | 883 | * This method is called every game frame, regardless if the world steps or not. |
885 | 884 | * |
886 | 885 | * @method Phaser.Physics.Arcade.Body#preUpdate |
887 | 886 | * @since 3.17.0 |
888 | | - * |
| 887 | + * |
889 | 888 | * @param {boolean} willStep - Will this Body run an update as well? |
890 | 889 | * @param {number} delta - The delta time, in seconds, elapsed since the last frame. |
891 | 890 | */ |
@@ -923,9 +922,9 @@ var Body = new Class({ |
923 | 922 |
|
924 | 923 | /** |
925 | 924 | * Performs a single physics step and updates the body velocity, angle, speed and other properties. |
926 | | - * |
| 925 | + * |
927 | 926 | * This method can be called multiple times per game frame, depending on the physics step rate. |
928 | | - * |
| 927 | + * |
929 | 928 | * The results are synced back to the Game Object in `postUpdate`. |
930 | 929 | * |
931 | 930 | * @method Phaser.Physics.Arcade.Body#update |
@@ -967,7 +966,7 @@ var Body = new Class({ |
967 | 966 |
|
968 | 967 | /** |
969 | 968 | * Feeds the Body results back into the parent Game Object. |
970 | | - * |
| 969 | + * |
971 | 970 | * This method is called every game frame, regardless if the world steps or not. |
972 | 971 | * |
973 | 972 | * @method Phaser.Physics.Arcade.Body#postUpdate |
@@ -1116,6 +1115,7 @@ var Body = new Class({ |
1116 | 1115 | if (y === undefined) { y = x; } |
1117 | 1116 |
|
1118 | 1117 | this.offset.set(x, y); |
| 1118 | + this.updateCenter(); |
1119 | 1119 |
|
1120 | 1120 | return this; |
1121 | 1121 | }, |
@@ -1306,7 +1306,21 @@ var Body = new Class({ |
1306 | 1306 | */ |
1307 | 1307 | hitTest: function (x, y) |
1308 | 1308 | { |
1309 | | - return (this.isCircle) ? CircleContains(this, x, y) : RectangleContains(this, x, y); |
| 1309 | + if (!this.isCircle) |
| 1310 | + { |
| 1311 | + return RectangleContains(this, x, y); |
| 1312 | + } |
| 1313 | + |
| 1314 | + // Check if x/y are within the bounds first |
| 1315 | + if (this.radius > 0 && x >= this.left && x <= this.right && y >= this.top && y <= this.bottom) |
| 1316 | + { |
| 1317 | + var dx = (this.center.x - x) * (this.center.x - x); |
| 1318 | + var dy = (this.center.y - y) * (this.center.y - y); |
| 1319 | + |
| 1320 | + return (dx + dy) <= (this.radius * this.radius); |
| 1321 | + } |
| 1322 | + |
| 1323 | + return false; |
1310 | 1324 | }, |
1311 | 1325 |
|
1312 | 1326 | /** |
@@ -1504,7 +1518,7 @@ var Body = new Class({ |
1504 | 1518 |
|
1505 | 1519 | /** |
1506 | 1520 | * Sets whether this Body collides with the world boundary. |
1507 | | - * |
| 1521 | + * |
1508 | 1522 | * Optionally also sets the World Bounce values. If the `Body.worldBounce` is null, it's set to a new Vec2 first. |
1509 | 1523 | * |
1510 | 1524 | * @method Phaser.Physics.Arcade.Body#setCollideWorldBounds |
|
0 commit comments