2015-03-23 23:27:14 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2015-03-23 23:27:14 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2015-03-01 07:00:17 +00:00
|
|
|
/**
|
2015-03-23 19:56:23 +00:00
|
|
|
* The AutoCull Component is responsible for providing methods that check if a Game Object is within the bounds of the World Camera.
|
|
|
|
* It is used by the InWorld component.
|
2015-03-01 07:00:17 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*/
|
2015-02-17 05:15:04 +00:00
|
|
|
Phaser.Component.AutoCull = function () {};
|
|
|
|
|
|
|
|
Phaser.Component.AutoCull.prototype = {
|
|
|
|
|
|
|
|
/**
|
2015-03-23 19:56:23 +00:00
|
|
|
* A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame.
|
|
|
|
* If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`.
|
|
|
|
* This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely.
|
|
|
|
*
|
|
|
|
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
|
|
|
|
* or you have tested performance and find it acceptable.
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
2015-03-23 19:56:23 +00:00
|
|
|
* @property {boolean} autoCull
|
2015-02-17 05:15:04 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
autoCull: false,
|
|
|
|
|
|
|
|
/**
|
2015-03-23 19:56:23 +00:00
|
|
|
* Checks if the Game Objects bounds intersect with the Game Camera bounds.
|
|
|
|
* Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds.
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
2015-03-23 19:56:23 +00:00
|
|
|
* @property {boolean} inCamera
|
2015-02-17 05:15:04 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
inCamera: {
|
|
|
|
|
|
|
|
get: function() {
|
|
|
|
|
|
|
|
if (!this.autoCull && !this.checkWorldBounds)
|
|
|
|
{
|
|
|
|
this._bounds.copyFrom(this.getBounds());
|
|
|
|
this._bounds.x += this.game.camera.view.x;
|
|
|
|
this._bounds.y += this.game.camera.view.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.game.world.camera.view.intersects(this._bounds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|