@@ -31,6 +31,9 @@ var RectangleContains = require('../../geom/rectangle/Contains');
3131 * @property {number } [bounds.height] - [description]
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+
3437/**
3538 * @classdesc
3639 * [description]
@@ -67,18 +70,22 @@ var CameraManager = new Class({
6770 this . systems = scene . sys ;
6871
6972 /**
70- * The current Camera ID.
73+ * The ID that will be assigned to the next Camera that is created.
74+ * This is a bitmask value, meaning only up to 31 cameras can be created in total.
7175 *
72- * @name Phaser.Cameras.Scene2D.CameraManager#currentCameraId
73- * @type {number }
76+ * @name Phaser.Cameras.Scene2D.CameraManager#nextID
77+ * @type {integer }
7478 * @default 1
7579 * @readOnly
7680 * @since 3.0.0
7781 */
78- this . currentCameraId = 1 ;
82+ this . nextID = 1 ;
7983
8084 /**
8185 * An Array of the Camera objects being managed by this Camera Manager.
86+ * The Cameras are updated and rendered in the same order in which they appear in this array.
87+ * Do not directly add or remove entries to this array. However, you can move the contents
88+ * around the array should you wish to adjust the display order.
8289 *
8390 * @name Phaser.Cameras.Scene2D.CameraManager#cameras
8491 * @type {Phaser.Cameras.Scene2D.Camera[] }
@@ -87,7 +94,15 @@ var CameraManager = new Class({
8794 this . cameras = [ ] ;
8895
8996 /**
90- * The default Camera in the Camera Manager.
97+ * A handy reference to the 'main' camera. By default this is the first Camera the
98+ * Camera Manager creates. You can also set it directly, or use the `makeMain` argument
99+ * in the `add` and `addExisting` methods. It allows you to access it from your game:
100+ *
101+ * ```javascript
102+ * var cam = this.cameras.main;
103+ * ```
104+ *
105+ * Also see the properties `camera1`, `camera2` and so on.
91106 *
92107 * @name Phaser.Cameras.Scene2D.CameraManager#main
93108 * @type {Phaser.Cameras.Scene2D.Camera }
@@ -96,7 +111,7 @@ var CameraManager = new Class({
96111 this . main ;
97112
98113 /**
99- * This scale affects all cameras. It's used by Scale Manager.
114+ * This scale affects all cameras. It's used by the Scale Manager.
100115 *
101116 * @name Phaser.Cameras.Scene2D.CameraManager#baseScale
102117 * @type {number }
@@ -194,9 +209,9 @@ var CameraManager = new Class({
194209 this . main = camera ;
195210 }
196211
197- camera . id = this . currentCameraId ;
212+ camera . id = this . nextID ;
198213
199- this . currentCameraId = this . currentCameraId << 1 ;
214+ this . nextID = this . nextID << 1 ;
200215
201216 return camera ;
202217 } ,
@@ -208,21 +223,29 @@ var CameraManager = new Class({
208223 * @since 3.0.0
209224 *
210225 * @param {Phaser.Cameras.Scene2D.Camera } camera - [description]
226+ * @param {boolean } [makeMain=false] - [description]
211227 *
212228 * @return {Phaser.Cameras.Scene2D.Camera } [description]
213229 */
214- addExisting : function ( camera )
230+ addExisting : function ( camera , makeMain )
215231 {
232+ if ( makeMain === undefined ) { makeMain = false ; }
233+
216234 var index = this . cameras . indexOf ( camera ) ;
217235
218- if ( index == - 1 )
236+ if ( index === - 1 )
219237 {
220- camera . id = this . currentCameraId ;
221-
222- this . currentCameraId = this . currentCameraId << 1 ;
223-
224238 this . cameras . push ( camera ) ;
225239
240+ camera . id = this . nextID ;
241+
242+ this . nextID = this . nextID << 1 ;
243+
244+ if ( makeMain )
245+ {
246+ this . main = camera ;
247+ }
248+
226249 return camera ;
227250 }
228251
@@ -304,15 +327,17 @@ var CameraManager = new Class({
304327 *
305328 * @param {string } name - [description]
306329 *
307- * @return {Phaser.Cameras.Scene2D.Camera } [description]
330+ * @return {? Phaser.Cameras.Scene2D.Camera } [description]
308331 */
309332 getCamera : function ( name )
310333 {
311- for ( var i = 0 ; i < this . cameras . length ; i ++ )
334+ var cameras = this . cameras ;
335+
336+ for ( var i = 0 ; i < cameras . length ; i ++ )
312337 {
313- if ( this . cameras [ i ] . name === name )
338+ if ( cameras [ i ] . name === name )
314339 {
315- return this . cameras [ i ] ;
340+ return cameras [ i ] ;
316341 }
317342 }
318343
@@ -389,18 +414,20 @@ var CameraManager = new Class({
389414 */
390415 render : function ( renderer , children , interpolation )
391416 {
417+ var scene = this . scene ;
392418 var cameras = this . cameras ;
393419 var baseScale = this . baseScale ;
420+ var resolution = renderer . config . resolution ;
394421
395- for ( var i = 0 , l = cameras . length ; i < l ; ++ i )
422+ for ( var i = 0 ; i < this . cameras . length ; i ++ )
396423 {
397424 var camera = cameras [ i ] ;
398425
399- if ( camera . visible )
426+ if ( camera . visible && camera . alpha > 0 )
400427 {
401- camera . preRender ( baseScale , renderer . config . resolution ) ;
428+ camera . preRender ( baseScale , resolution ) ;
402429
403- renderer . render ( this . scene , children , interpolation , camera ) ;
430+ renderer . render ( scene , children , interpolation , camera ) ;
404431 }
405432 }
406433 } ,
@@ -422,7 +449,7 @@ var CameraManager = new Class({
422449
423450 this . cameras = [ ] ;
424451
425- this . currentCameraId = 1 ;
452+ this . nextID = 1 ;
426453
427454 this . main = this . add ( ) ;
428455
@@ -440,7 +467,7 @@ var CameraManager = new Class({
440467 */
441468 update : function ( timestep , delta )
442469 {
443- for ( var i = 0 , l = this . cameras . length ; i < l ; ++ i )
470+ for ( var i = 0 ; i < this . cameras . length ; i ++ )
444471 {
445472 this . cameras [ i ] . update ( timestep , delta ) ;
446473 }
@@ -457,7 +484,7 @@ var CameraManager = new Class({
457484 */
458485 resize : function ( width , height )
459486 {
460- for ( var i = 0 , l = this . cameras . length ; i < l ; ++ i )
487+ for ( var i = 0 ; i < this . cameras . length ; i ++ )
461488 {
462489 this . cameras [ i ] . setSize ( width , height ) ;
463490 }
@@ -504,6 +531,195 @@ var CameraManager = new Class({
504531
505532 this . scene = null ;
506533 this . systems = null ;
534+ } ,
535+
536+ /**
537+ * A reference to Camera 1 in the Camera Manager.
538+ *
539+ * Create additional cameras using the `add` method.
540+ *
541+ * @name Phaser.Cameras.Scene2D.CameraManager#camera1
542+ * @type {Phaser.Cameras.Scene2D.Camera }
543+ * @readOnly
544+ * @since 3.11.0
545+ */
546+ camera1 : {
547+
548+ get : function ( )
549+ {
550+ return this . cameras [ 0 ] ;
551+ }
552+
553+ } ,
554+
555+ /**
556+ * A reference to Camera 2 in the Camera Manager.
557+ *
558+ * This will be `undefined` by default unless you have created new cameras via `add` or `addExisting`.
559+ *
560+ * @name Phaser.Cameras.Scene2D.CameraManager#camera2
561+ * @type {Phaser.Cameras.Scene2D.Camera }
562+ * @readOnly
563+ * @since 3.11.0
564+ */
565+ camera2 : {
566+
567+ get : function ( )
568+ {
569+ return this . cameras [ 1 ] ;
570+ }
571+
572+ } ,
573+
574+ /**
575+ * A reference to Camera 3 in the Camera Manager.
576+ *
577+ * This will be `undefined` by default unless you have created new cameras via `add` or `addExisting`.
578+ *
579+ * @name Phaser.Cameras.Scene2D.CameraManager#camera3
580+ * @type {Phaser.Cameras.Scene2D.Camera }
581+ * @readOnly
582+ * @since 3.11.0
583+ */
584+ camera3 : {
585+
586+ get : function ( )
587+ {
588+ return this . cameras [ 2 ] ;
589+ }
590+
591+ } ,
592+
593+ /**
594+ * A reference to Camera 4 in the Camera Manager.
595+ *
596+ * This will be `undefined` by default unless you have created new cameras via `add` or `addExisting`.
597+ *
598+ * @name Phaser.Cameras.Scene2D.CameraManager#camera4
599+ * @type {Phaser.Cameras.Scene2D.Camera }
600+ * @readOnly
601+ * @since 3.11.0
602+ */
603+ camera4 : {
604+
605+ get : function ( )
606+ {
607+ return this . cameras [ 3 ] ;
608+ }
609+
610+ } ,
611+
612+ /**
613+ * A reference to Camera 5 in the Camera Manager.
614+ *
615+ * This will be `undefined` by default unless you have created new cameras via `add` or `addExisting`.
616+ *
617+ * @name Phaser.Cameras.Scene2D.CameraManager#camera5
618+ * @type {Phaser.Cameras.Scene2D.Camera }
619+ * @readOnly
620+ * @since 3.11.0
621+ */
622+ camera5 : {
623+
624+ get : function ( )
625+ {
626+ return this . cameras [ 4 ] ;
627+ }
628+
629+ } ,
630+
631+ /**
632+ * A reference to Camera 6 in the Camera Manager.
633+ *
634+ * This will be `undefined` by default unless you have created new cameras via `add` or `addExisting`.
635+ *
636+ * @name Phaser.Cameras.Scene2D.CameraManager#camera6
637+ * @type {Phaser.Cameras.Scene2D.Camera }
638+ * @readOnly
639+ * @since 3.11.0
640+ */
641+ camera6 : {
642+
643+ get : function ( )
644+ {
645+ return this . cameras [ 5 ] ;
646+ }
647+
648+ } ,
649+
650+ /**
651+ * A reference to Camera 7 in the Camera Manager.
652+ *
653+ * This will be `undefined` by default unless you have created new cameras via `add` or `addExisting`.
654+ *
655+ * @name Phaser.Cameras.Scene2D.CameraManager#camera7
656+ * @type {Phaser.Cameras.Scene2D.Camera }
657+ * @readOnly
658+ * @since 3.11.0
659+ */
660+ camera7 : {
661+
662+ get : function ( )
663+ {
664+ return this . cameras [ 6 ] ;
665+ }
666+
667+ } ,
668+
669+ /**
670+ * A reference to Camera 8 in the Camera Manager.
671+ *
672+ * This will be `undefined` by default unless you have created new cameras via `add` or `addExisting`.
673+ *
674+ * @name Phaser.Cameras.Scene2D.CameraManager#camera8
675+ * @type {Phaser.Cameras.Scene2D.Camera }
676+ * @readOnly
677+ * @since 3.11.0
678+ */
679+ camera8 : {
680+
681+ get : function ( )
682+ {
683+ return this . cameras [ 7 ] ;
684+ }
685+
686+ } ,
687+
688+ /**
689+ * A reference to Camera 9 in the Camera Manager.
690+ *
691+ * This will be `undefined` by default unless you have created new cameras via `add` or `addExisting`.
692+ *
693+ * @name Phaser.Cameras.Scene2D.CameraManager#camera9
694+ * @type {Phaser.Cameras.Scene2D.Camera }
695+ * @readOnly
696+ * @since 3.11.0
697+ */
698+ camera9 : {
699+
700+ get : function ( )
701+ {
702+ return this . cameras [ 8 ] ;
703+ }
704+
705+ } ,
706+ /**
707+ * A reference to Camera 10 in the Camera Manager.
708+ *
709+ * This will be `undefined` by default unless you have created new cameras via `add` or `addExisting`.
710+ *
711+ * @name Phaser.Cameras.Scene2D.CameraManager#camera10
712+ * @type {Phaser.Cameras.Scene2D.Camera }
713+ * @readOnly
714+ * @since 3.11.0
715+ */
716+ camera10 : {
717+
718+ get : function ( )
719+ {
720+ return this . cameras [ 9 ] ;
721+ }
722+
507723 }
508724
509725} ) ;
0 commit comments