Skip to content

Commit 08c9513

Browse files
committed
Improving the Component documentation.
1 parent 85c8f60 commit 08c9513

2 files changed

Lines changed: 29 additions & 15 deletions

File tree

src/gameobjects/components/AutoCull.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
* AutoCull Component Features.
2+
* The AutoCull Component is responsible for providing methods that check if a Game Object is within the bounds of the World Camera.
3+
* It is used by the InWorld component.
34
*
45
* @class
56
*/
@@ -8,19 +9,23 @@ Phaser.Component.AutoCull = function () {};
89
Phaser.Component.AutoCull.prototype = {
910

1011
/**
11-
* Should this Sprite be automatically culled if out of range of the camera?
12-
* A culled sprite has its renderable property set to 'false'.
13-
* Be advised this is quite an expensive operation, as it has to calculate the bounds of the object every frame, so only enable it if you really need it.
12+
* A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame.
13+
* If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`.
14+
* This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely.
15+
*
16+
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
17+
* or you have tested performance and find it acceptable.
1418
*
15-
* @property {boolean} autoCull - A flag indicating if the Sprite should be automatically camera culled or not.
19+
* @property {boolean} autoCull
1620
* @default
1721
*/
1822
autoCull: false,
1923

2024
/**
21-
* Checks if the Sprite bounds are within the game camera, otherwise false if fully outside of it.
25+
* Checks if the Game Objects bounds intersect with the Game Camera bounds.
26+
* Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds.
2227
*
23-
* @property {boolean} inCamera - True if the Sprite bounds is within the game camera, even if only partially. Otherwise false if fully outside of it.
28+
* @property {boolean} inCamera
2429
* @readonly
2530
*/
2631
inCamera: {

src/gameobjects/components/InWorld.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/**
2-
* InWorld Component Features.
2+
* The InWorld component checks if a Game Object is within the Game World Bounds.
3+
* An object is considered as being "in bounds" so long as its own bounds intersects at any point with the World bounds.
4+
* If the AutoCull component is enabled on the Game Object then it will check the Game Object against the Camera bounds as well.
35
*
46
* @class
57
*/
@@ -59,30 +61,37 @@ Phaser.Component.InWorld.preUpdate = function () {
5961
Phaser.Component.InWorld.prototype = {
6062

6163
/**
62-
* If true the Sprite checks if it is still within the world each frame, when it leaves the world it dispatches Sprite.events.onOutOfBounds
63-
* and optionally kills the sprite (if Sprite.outOfBoundsKill is true). By default this is disabled because the Sprite has to calculate its
64-
* bounds every frame to support it, and not all games need it. Enable it by setting the value to true.
64+
* If this is set to `true` the Game Object checks if it is within the World bounds each frame.
65+
* When it is no longer within or intersecting the world bounds it dispatches the `onOutOfBounds` event.
66+
* If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event.
67+
* It also optionally kills the Game Object if `outOfBoundsKill` is `true`.
68+
* When `checkWorldBounds` is enabled it forces the Game Object has to calculate its full bounds every frame.
69+
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
70+
* or you have tested performance and find it acceptable.
71+
*
6572
* @property {boolean} checkWorldBounds
6673
* @default
6774
*/
6875
checkWorldBounds: false,
6976

7077
/**
71-
* @property {boolean} outOfBoundsKill - If true Sprite.kill is called as soon as Sprite.inWorld returns false, as long as Sprite.checkWorldBounds is true.
78+
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
79+
*
80+
* @property {boolean} outOfBoundsKill
7281
* @default
7382
*/
7483
outOfBoundsKill: false,
7584

7685
/**
77-
* @property {boolean} _outOfBoundsFired - Internal cache var.
86+
* @property {boolean} _outOfBoundsFired - Internal state var.
7887
* @private
7988
*/
8089
_outOfBoundsFired: false,
8190

8291
/**
83-
* Checks if the Sprite bounds are within the game world, otherwise false if fully outside of it.
92+
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
8493
*
85-
* @property {boolean} inWorld - True if the Sprite bounds is within the game world, even if only partially. Otherwise false if fully outside of it.
94+
* @property {boolean} inWorld
8695
* @readonly
8796
*/
8897
inWorld: {

0 commit comments

Comments
 (0)