Skip to content

Commit c2fbad8

Browse files
committed
Added jsdocs. Now 100% complete!
1 parent ba9890e commit c2fbad8

2 files changed

Lines changed: 110 additions & 46 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
### Camera - New Features, Updates and Fixes
66

7+
* All of the 2D Camera classes are now 100% covered by JSDocs!
78
* `Camera.alpha` (and its related method `Camera.setAlpha`) allows you to set an alpha level for the entire camera. This impacts everything it is rendering, even if those objects also have their own alpha values too. You can tween the property to make the camera contents fade in / out, or otherwise set it as needed in your game.
89
* `Camera.deadzone` (and its related method `Camera.setDeadzone`) allows you to specify the deadzone for a camera. The deadzone is a rectangular region used when a camera is following a target. If the target is within the deadzone then the camera will not scroll. As soon as the target leaves the deadzone, the camera will begin tracking it (applying lerp if needed.) It allows you to set a region of the camera in which a player can move freely before tracking begins. The deadzone is re-centered on the camera mid point every frame, meaning you can also use the rectangle for other in-game chcecks as needed.
10+
* `Camera.pan` is a new Camera Effect that allows you to control automatic camera pans between points in your game world. You can specify a duration and ease type for the pan, and it'll emit events just like all other camera effects, so you can hook into the start, update and completion of the pan. See the examples and docs for more details.
11+
* `Camera.zoom` is a new Camera Effect that allows you to control automatic camera zooming. You can specify a duration and ease type for the zoom, as well as the zoom factor of course, and it'll emit events just like all other camera effects, so you can hook into the start, update and completion of the zoom. Used in combination with the new Pan effect you can zoom and pan around with ease. See the examples and docs for more details.
912
* `Camera.midPoint` is a new Vec2 property that is updated every frame. Use it to obtain exactly where in the world the center of the camera is currently looking.
1013
* `Camera.displayWidth` is a new property that returns the display width of the camera, factoring in the current zoom level.
1114
* `Camera.displayHeight` is a new property that returns the display height of the camera, factoring in the current zoom level.

src/cameras/2d/CameraManager.js

Lines changed: 107 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,54 @@ var RectangleContains = require('../../geom/rectangle/Contains');
1313
/**
1414
* @typedef {object} InputJSONCameraObject
1515
*
16-
* @property {string} [name=''] - [description]
17-
* @property {integer} [x=0] - [description]
18-
* @property {integer} [y=0] - [description]
19-
* @property {integer} [width] - [description]
20-
* @property {integer} [height] - [description]
21-
* @property {float} [zoom=1] - [description]
22-
* @property {float} [rotation=0] - [description]
23-
* @property {boolean} [roundPixels=false] - [description]
24-
* @property {float} [scrollX=0] - [description]
25-
* @property {float} [scrollY=0] - [description]
26-
* @property {(false|string)} [backgroundColor=false] - [description]
27-
* @property {?object} [bounds] - [description]
28-
* @property {number} [bounds.x=0] - [description]
29-
* @property {number} [bounds.y=0] - [description]
30-
* @property {number} [bounds.width] - [description]
31-
* @property {number} [bounds.height] - [description]
16+
* @property {string} [name=''] - The name of the Camera.
17+
* @property {integer} [x=0] - The horizontal position of the Camera viewport.
18+
* @property {integer} [y=0] - The vertical position of the Camera viewport.
19+
* @property {integer} [width] - The width of the Camera viewport.
20+
* @property {integer} [height] - The height of the Camera viewport.
21+
* @property {float} [zoom=1] - The default zoom level of the Camera.
22+
* @property {float} [rotation=0] - The rotation of the Camera, in radians.
23+
* @property {boolean} [roundPixels=false] - Should the Camera round pixels before rendering?
24+
* @property {float} [scrollX=0] - The horizontal scroll position of the Camera.
25+
* @property {float} [scrollY=0] - The vertical scroll position of the Camera.
26+
* @property {(false|string)} [backgroundColor=false] - A CSS color string controlling the Camera background color.
27+
* @property {?object} [bounds] - Defines the Camera bounds.
28+
* @property {number} [bounds.x=0] - The top-left extent of the Camera bounds.
29+
* @property {number} [bounds.y=0] - The top-left extent of the Camera bounds.
30+
* @property {number} [bounds.width] - The width of the Camera bounds.
31+
* @property {number} [bounds.height] - The height of the Camera bounds.
3232
*/
3333

34-
// TODO stop it assigning more than 32 cameras (or whatever the limit is)
35-
// The remove method leaves gaps in the ID list
36-
3734
/**
3835
* @classdesc
39-
* [description]
36+
* The Camera Manager is a plugin that belongs to a Scene and is responsible for managing all of the Scene Cameras.
37+
*
38+
* By default you can access the Camera Manager from within a Scene using `this.cameras`, although this can be changed
39+
* in your game config.
40+
*
41+
* The Camera Manager can manage up to 31 unique Cameras. You can use the properties `camera1` through to `camera10`
42+
* for quick and easy access to the first 10 cameras you define.
43+
*
44+
* Create new Cameras using the `add` method. Or extend the Camera class with your own addition code and then add
45+
* the new Camera in using the `addExisting` method.
46+
*
47+
* Cameras provide a view into your game world, and can be positioned, rotated, zoomed and scrolled accordingly.
48+
*
49+
* A Camera consists of two elements: The viewport and the scroll values.
50+
*
51+
* The viewport is the physical position and size of the Camera within your game. Cameras, by default, are
52+
* created the same size as your game, but their position and size can be set to anything. This means if you
53+
* wanted to create a camera that was 320x200 in size, positioned in the bottom-right corner of your game,
54+
* you'd adjust the viewport to do that (using methods like `setViewport` and `setSize`).
55+
*
56+
* If you wish to change where the Camera is looking in your game, then you scroll it. You can do this
57+
* via the properties `scrollX` and `scrollY` or the method `setScroll`. Scrolling has no impact on the
58+
* viewport, and changing the viewport has no impact on the scrolling.
59+
*
60+
* By default a Camera will render all Game Objects it can see. You can change this using the `ignore` method,
61+
* allowing you to filter Game Objects out on a per-Camera basis.
62+
*
63+
* A Camera also has built-in special effects including Fade, Flash and Camera Shake.
4064
*
4165
* @class CameraManager
4266
* @memberOf Phaser.Cameras.Scene2D
@@ -174,19 +198,30 @@ var CameraManager = new Class({
174198
},
175199

176200
/**
177-
* [description]
201+
* Adds a new Camera into the Camera Manager. The Camera Manager can support up to 31 different Cameras.
202+
*
203+
* Each Camera has its own viewport, which controls the size of the Camera and its position within the canvas.
204+
*
205+
* Use the `Camera.scrollX` and `Camera.scrollY` properties to change where the Camera is looking, or the
206+
* Camera methods such as `centerOn`. Cameras also have built in special effects, such as fade, flash, shake,
207+
* pan and zoom.
208+
*
209+
* By default Cameras are transparent and will render anything that they can see based on their `scrollX`
210+
* and `scrollY` values. Game Objects can be set to be ignored by a Camera by using the `Camera.ignore` method.
211+
*
212+
* See the Camera class documentation for more details.
178213
*
179214
* @method Phaser.Cameras.Scene2D.CameraManager#add
180215
* @since 3.0.0
181216
*
182-
* @param {number} [x=0] - [description]
183-
* @param {number} [y=0] - [description]
184-
* @param {number} [width] - [description]
185-
* @param {number} [height] - [description]
186-
* @param {boolean} [makeMain=false] - [description]
187-
* @param {string} [name=''] - [description]
217+
* @param {integer} [x=0] - The horizontal position of the Camera viewport.
218+
* @param {integer} [y=0] - The vertical position of the Camera viewport.
219+
* @param {integer} [width] - The width of the Camera viewport. If not given it'll be the game config size.
220+
* @param {integer} [height] - The height of the Camera viewport. If not given it'll be the game config size.
221+
* @param {boolean} [makeMain=false] - Set this Camera as being the 'main' camera. This just makes the property `main` a reference to it.
222+
* @param {string} [name=''] - The name of the Camera.
188223
*
189-
* @return {Phaser.Cameras.Scene2D.Camera} [description]
224+
* @return {Phaser.Cameras.Scene2D.Camera} The newly created Camera.
190225
*/
191226
add: function (x, y, width, height, makeMain, name)
192227
{
@@ -217,15 +252,22 @@ var CameraManager = new Class({
217252
},
218253

219254
/**
220-
* [description]
255+
* Adds an existing Camera into the Camera Manager.
256+
*
257+
* The Camera should either be a `Phaser.Cameras.Scene2D.Camera` instance, or a class that extends from it.
258+
*
259+
* The Camera will be assigned an ID, which is used for Game Object exclusion and then added to the
260+
* manager. As long as it doesn't already exist in the manager it will be added then returned.
261+
*
262+
* If this method returns `null` then the Camera already exists in this Camera Manager.
221263
*
222264
* @method Phaser.Cameras.Scene2D.CameraManager#addExisting
223265
* @since 3.0.0
224266
*
225-
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
226-
* @param {boolean} [makeMain=false] - [description]
267+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to be added to the Camera Manager.
268+
* @param {boolean} [makeMain=false] - Set this Camera as being the 'main' camera. This just makes the property `main` a reference to it.
227269
*
228-
* @return {Phaser.Cameras.Scene2D.Camera} [description]
270+
* @return {?Phaser.Cameras.Scene2D.Camera} The Camera that was added to the Camera Manager, or `null` if it couldn't be added.
229271
*/
230272
addExisting: function (camera, makeMain)
231273
{
@@ -253,14 +295,16 @@ var CameraManager = new Class({
253295
},
254296

255297
/**
256-
* [description]
298+
* Populates this Camera Manager based on the given configuration object, or an array of config objects.
299+
*
300+
* See the `InputJSONCameraObject` documentation for details of the object structure.
257301
*
258302
* @method Phaser.Cameras.Scene2D.CameraManager#fromJSON
259303
* @since 3.0.0
260304
*
261-
* @param {(InputJSONCameraObject|InputJSONCameraObject[])} config - [description]
305+
* @param {(InputJSONCameraObject|InputJSONCameraObject[])} config - A Camera configuration object, or an array of them, to be added to this Camera Manager.
262306
*
263-
* @return {Phaser.Cameras.Scene2D.CameraManager} [description]
307+
* @return {Phaser.Cameras.Scene2D.CameraManager} This Camera Manager instance.
264308
*/
265309
fromJSON: function (config)
266310
{
@@ -320,14 +364,17 @@ var CameraManager = new Class({
320364
},
321365

322366
/**
323-
* [description]
367+
* Gets a Camera based on its name.
368+
*
369+
* Camera names are optional and don't have to be set, so this method is only of any use if you
370+
* have given your Cameras unique names.
324371
*
325372
* @method Phaser.Cameras.Scene2D.CameraManager#getCamera
326373
* @since 3.0.0
327374
*
328-
* @param {string} name - [description]
375+
* @param {string} name - The name of the Camera.
329376
*
330-
* @return {?Phaser.Cameras.Scene2D.Camera} [description]
377+
* @return {?Phaser.Cameras.Scene2D.Camera} The first Camera with a name matching the given string, otherwise `null`.
331378
*/
332379
getCamera: function (name)
333380
{
@@ -380,12 +427,18 @@ var CameraManager = new Class({
380427
},
381428

382429
/**
383-
* [description]
430+
* Removes the given Camera from this Camera Manager.
431+
*
432+
* If found in the Camera Manager it will be immediately removed from the local cameras array.
433+
* If also currently the 'main' camera, 'main' will be reset to be camera 0.
434+
*
435+
* The removed Camera is not destroyed. If you also wish to destroy the Camera, you should call
436+
* `Camera.destroy` on it, so that it clears all references to the Camera Manager.
384437
*
385438
* @method Phaser.Cameras.Scene2D.CameraManager#remove
386439
* @since 3.0.0
387440
*
388-
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
441+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to be removed from this Camera Manager.
389442
*/
390443
remove: function (camera)
391444
{
@@ -403,9 +456,13 @@ var CameraManager = new Class({
403456
},
404457

405458
/**
406-
* [description]
459+
* The internal render method. This is called automatically by the Scene and should not be invoked directly.
460+
*
461+
* It will iterate through all local cameras and render them in turn, as long as they're visible and have
462+
* an alpha level > 0.
407463
*
408464
* @method Phaser.Cameras.Scene2D.CameraManager#render
465+
* @protected
409466
* @since 3.0.0
410467
*
411468
* @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The Renderer that will render the children to this camera.
@@ -433,12 +490,15 @@ var CameraManager = new Class({
433490
},
434491

435492
/**
436-
* [description]
493+
* Resets this Camera Manager.
494+
*
495+
* This will iterate through all current Cameras, destroying them all, then it will reset the
496+
* cameras array, reset the ID counter and create 1 new single camera using the default values.
437497
*
438498
* @method Phaser.Cameras.Scene2D.CameraManager#resetAll
439499
* @since 3.0.0
440500
*
441-
* @return {Phaser.Cameras.Scene2D.Camera} [description]
501+
* @return {Phaser.Cameras.Scene2D.Camera} The freshly created main Camera.
442502
*/
443503
resetAll: function ()
444504
{
@@ -457,13 +517,14 @@ var CameraManager = new Class({
457517
},
458518

459519
/**
460-
* [description]
520+
* The main update loop. Called automatically when the Scene steps.
461521
*
462522
* @method Phaser.Cameras.Scene2D.CameraManager#update
523+
* @protected
463524
* @since 3.0.0
464525
*
465-
* @param {number} timestep - [description]
466-
* @param {number} delta - [description]
526+
* @param {number} timestep - The timestep value.
527+
* @param {number} delta - The delta value since the last frame.
467528
*/
468529
update: function (timestep, delta)
469530
{

0 commit comments

Comments
 (0)