Skip to content

Commit 439cefd

Browse files
committed
ArcadePhysics.Body.hitTest(x, y) will return a boolean based on if the given world coordinate are within the Body or not.
Fixed jsdoc method tags in Body.
1 parent 03b8088 commit 439cefd

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ New Features
8989
* SoundManager.remove(sound) now lets you remove a sound from the SoundManager, destroying it in the process.
9090
* Sound.destroy will remove a sound and all local references it holds, optionally removing itself from the SoundManager as well.
9191
* SoundManager.removeByKey(key) will remove all sounds from the SoundManager that have a key matching the given value.
92+
* ArcadePhysics.Body.hitTest(x, y) will return a boolean based on if the given world coordinate are within the Body or not.
9293

9394

9495
Bug Fixes

src/physics/arcade/Body.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ Phaser.Physics.Arcade.Body.prototype = {
328328
/**
329329
* Internal method.
330330
*
331-
* @method Phaser.Physics.Arcade#updateBounds
331+
* @method Phaser.Physics.Arcade.Body#updateBounds
332332
* @protected
333333
*/
334334
updateBounds: function () {
@@ -354,7 +354,7 @@ Phaser.Physics.Arcade.Body.prototype = {
354354
/**
355355
* Internal method.
356356
*
357-
* @method Phaser.Physics.Arcade#preUpdate
357+
* @method Phaser.Physics.Arcade.Body#preUpdate
358358
* @protected
359359
*/
360360
preUpdate: function () {
@@ -429,7 +429,7 @@ Phaser.Physics.Arcade.Body.prototype = {
429429
/**
430430
* Internal method.
431431
*
432-
* @method Phaser.Physics.Arcade#postUpdate
432+
* @method Phaser.Physics.Arcade.Body#postUpdate
433433
* @protected
434434
*/
435435
postUpdate: function () {
@@ -502,7 +502,7 @@ Phaser.Physics.Arcade.Body.prototype = {
502502
/**
503503
* Removes this bodies reference to its parent sprite, freeing it up for gc.
504504
*
505-
* @method Phaser.Physics.Arcade#destroy
505+
* @method Phaser.Physics.Arcade.Body#destroy
506506
*/
507507
destroy: function () {
508508

@@ -513,7 +513,7 @@ Phaser.Physics.Arcade.Body.prototype = {
513513
/**
514514
* Internal method.
515515
*
516-
* @method Phaser.Physics.Arcade#checkWorldBounds
516+
* @method Phaser.Physics.Arcade.Body#checkWorldBounds
517517
* @protected
518518
*/
519519
checkWorldBounds: function () {
@@ -551,7 +551,7 @@ Phaser.Physics.Arcade.Body.prototype = {
551551
* So it could be smaller or larger than the parent Sprite. You can also control the x and y offset, which
552552
* is the position of the Body relative to the top-left of the Sprite.
553553
*
554-
* @method Phaser.Physics.Arcade#setSize
554+
* @method Phaser.Physics.Arcade.Body#setSize
555555
* @param {number} width - The width of the Body.
556556
* @param {number} height - The height of the Body.
557557
* @param {number} offsetX - The X offset of the Body from the Sprite position.
@@ -577,9 +577,9 @@ Phaser.Physics.Arcade.Body.prototype = {
577577
/**
578578
* Resets all Body values (velocity, acceleration, rotation, etc)
579579
*
580-
* @method Phaser.Physics.Arcade#reset
580+
* @method Phaser.Physics.Arcade.Body#reset
581581
* @param {number} x - The new x position of the Body.
582-
* @param {number} y - The new x position of the Body.
582+
* @param {number} y - The new y position of the Body.
583583
*/
584584
reset: function (x, y) {
585585

@@ -605,6 +605,20 @@ Phaser.Physics.Arcade.Body.prototype = {
605605

606606
},
607607

608+
/**
609+
* Tests if a world point lies within this Body.
610+
*
611+
* @method Phaser.Physics.Arcade.Body#hitTest
612+
* @param {number} x - The world x coordinate to test.
613+
* @param {number} y - The world y coordinate to test.
614+
* @return {boolean} True if the given coordinates are inside this Body, otherwise false.
615+
*/
616+
hitTest: function (x, y) {
617+
618+
return Phaser.Rectangle.contains(this, x, y);
619+
620+
},
621+
608622
/**
609623
* Returns true if the bottom of this Body is in contact with either the world bounds or a tile.
610624
*

0 commit comments

Comments
 (0)