mirror of
https://github.com/photonstorm/phaser
synced 2024-12-18 00:53:42 +00:00
35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
*/
|
|
|
|
/**
|
|
* The Overlap component allows a Game Object to check if it overlaps with the bounds of another Game Object.
|
|
*
|
|
* @class
|
|
*/
|
|
Phaser.Component.Overlap = function () {};
|
|
|
|
Phaser.Component.Overlap.prototype = {
|
|
|
|
/**
|
|
* Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object,
|
|
* which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a `getBounds` method and result.
|
|
*
|
|
* This check ignores the `hitArea` property if set and runs a `getBounds` comparison on both objects to determine the result.
|
|
*
|
|
* Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency.
|
|
* It should be fine for low-volume testing where physics isn't required.
|
|
*
|
|
* @method
|
|
* @param {Phaser.Sprite|Phaser.Image|Phaser.TileSprite|Phaser.Button|PIXI.DisplayObject} displayObject - The display object to check against.
|
|
* @return {boolean} True if the bounds of this Game Object intersects at any point with the bounds of the given display object.
|
|
*/
|
|
overlap: function (displayObject) {
|
|
|
|
return Phaser.Rectangle.intersects(this.getBounds(), displayObject.getBounds());
|
|
|
|
}
|
|
|
|
};
|