@@ -94,6 +94,25 @@ var Camera = new Class({
9494 */
9595 this . scene ;
9696
97+ /**
98+ * A reference to the Game Scene Manager.
99+ *
100+ * @name Phaser.Cameras.Scene2D.Camera#sceneManager
101+ * @type {Phaser.Scenes.SceneManager }
102+ * @since 3.12.0
103+ */
104+ this . sceneManager ;
105+
106+ /**
107+ * A reference to the Game Config.
108+ *
109+ * @name Phaser.Cameras.Scene2D.Camera#config
110+ * @type {object }
111+ * @readOnly
112+ * @since 3.12.0
113+ */
114+ this . config ;
115+
97116 /**
98117 * The Camera ID. Assigned by the Camera Manager and used to handle camera exclusion.
99118 * This value is a bitmask.
@@ -115,6 +134,88 @@ var Camera = new Class({
115134 */
116135 this . name = '' ;
117136
137+ /**
138+ * The resolution of the Game, used in most Camera calculations.
139+ *
140+ * @name Phaser.Cameras.Scene2D.Camera#resolution
141+ * @type {number }
142+ * @readOnly
143+ * @since 3.12.0
144+ */
145+ this . resolution = 1 ;
146+
147+ /**
148+ * Should this camera round its pixel values to integers?
149+ *
150+ * @name Phaser.Cameras.Scene2D.Camera#roundPixels
151+ * @type {boolean }
152+ * @default false
153+ * @since 3.0.0
154+ */
155+ this . roundPixels = false ;
156+
157+ /**
158+ * Is this Camera visible or not?
159+ *
160+ * A visible camera will render and perform input tests.
161+ * An invisible camera will not render anything and will skip input tests.
162+ *
163+ * @name Phaser.Cameras.Scene2D.Camera#visible
164+ * @type {boolean }
165+ * @default true
166+ * @since 3.10.0
167+ */
168+ this . visible = true ;
169+
170+ /**
171+ * Is this Camera using a bounds to restrict scrolling movement?
172+ *
173+ * Set this property along with the bounds via `Camera.setBounds`.
174+ *
175+ * @name Phaser.Cameras.Scene2D.Camera#useBounds
176+ * @type {boolean }
177+ * @default false
178+ * @since 3.0.0
179+ */
180+ this . useBounds = false ;
181+
182+ /**
183+ * The World View is a Rectangle that defines the area of the 'world' the Camera is currently looking at.
184+ * This factors in the Camera viewport size, zoom and scroll position and is updated in the Camera preRender step.
185+ * If you have enabled Camera bounds the worldview will be clamped to those bounds accordingly.
186+ * You can use it for culling or intersection checks.
187+ *
188+ * @name Phaser.Cameras.Scene2D.Camera#worldView
189+ * @type {Phaser.Geom.Rectangle }
190+ * @readOnly
191+ * @since 3.11.0
192+ */
193+ this . worldView = new Rectangle ( ) ;
194+
195+ /**
196+ * Is this Camera dirty?
197+ *
198+ * A dirty Camera has had either its viewport size, bounds, scroll, rotation or zoom levels changed since the last frame.
199+ *
200+ * This flag is cleared during the `postRenderCamera` method of the renderer.
201+ *
202+ * @name Phaser.Cameras.Scene2D.Camera#dirty
203+ * @type {boolean }
204+ * @default true
205+ * @since 3.11.0
206+ */
207+ this . dirty = true ;
208+
209+ /**
210+ * Does this Camera allow the Game Objects it renders to receive input events?
211+ *
212+ * @name Phaser.Cameras.Scene2D.Camera#inputEnabled
213+ * @type {boolean }
214+ * @default true
215+ * @since 3.0.0
216+ */
217+ this . inputEnabled = true ;
218+
118219 /**
119220 * The x position of the Camera viewport, relative to the top-left of the game canvas.
120221 * The viewport is the area into which the camera renders.
@@ -139,16 +240,6 @@ var Camera = new Class({
139240 */
140241 this . _y = y ;
141242
142- /**
143- * The resolution of the Game, used in most Camera calculations.
144- *
145- * @name Phaser.Cameras.Scene2D.Camera#resolution
146- * @type {number }
147- * @readOnly
148- * @since 3.12.0
149- */
150- this . resolution = 1 ;
151-
152243 /**
153244 * Internal Camera X value multiplied by the resolution.
154245 *
@@ -215,41 +306,6 @@ var Camera = new Class({
215306 */
216307 this . _height = height ;
217308
218- /**
219- * Should this camera round its pixel values to integers?
220- *
221- * @name Phaser.Cameras.Scene2D.Camera#roundPixels
222- * @type {boolean }
223- * @default false
224- * @since 3.0.0
225- */
226- this . roundPixels = false ;
227-
228- /**
229- * Is this Camera visible or not?
230- *
231- * A visible camera will render and perform input tests.
232- * An invisible camera will not render anything and will skip input tests.
233- *
234- * @name Phaser.Cameras.Scene2D.Camera#visible
235- * @type {boolean }
236- * @default true
237- * @since 3.10.0
238- */
239- this . visible = true ;
240-
241- /**
242- * Is this Camera using a bounds to restrict scrolling movement?
243- *
244- * Set this property along with the bounds via `Camera.setBounds`.
245- *
246- * @name Phaser.Cameras.Scene2D.Camera#useBounds
247- * @type {boolean }
248- * @default false
249- * @since 3.0.0
250- */
251- this . useBounds = false ;
252-
253309 /**
254310 * The bounds the camera is restrained to during scrolling.
255311 *
@@ -260,43 +316,6 @@ var Camera = new Class({
260316 */
261317 this . _bounds = new Rectangle ( ) ;
262318
263- /**
264- * The World View is a Rectangle that defines the area of the 'world' the Camera is currently looking at.
265- * This factors in the Camera viewport size, zoom and scroll position and is updated in the Camera preRender step.
266- * If you have enabled Camera bounds the worldview will be clamped to those bounds accordingly.
267- * You can use it for culling or intersection checks.
268- *
269- * @name Phaser.Cameras.Scene2D.Camera#worldView
270- * @type {Phaser.Geom.Rectangle }
271- * @readOnly
272- * @since 3.11.0
273- */
274- this . worldView = new Rectangle ( ) ;
275-
276- /**
277- * Is this Camera dirty?
278- *
279- * A dirty Camera has had either its viewport size, bounds, scroll, rotation or zoom levels changed since the last frame.
280- *
281- * This flag is cleared during the `postRenderCamera` method of the renderer.
282- *
283- * @name Phaser.Cameras.Scene2D.Camera#dirty
284- * @type {boolean }
285- * @default true
286- * @since 3.11.0
287- */
288- this . dirty = true ;
289-
290- /**
291- * Does this Camera allow the Game Objects it renders to receive input events?
292- *
293- * @name Phaser.Cameras.Scene2D.Camera#inputEnabled
294- * @type {boolean }
295- * @default true
296- * @since 3.0.0
297- */
298- this . inputEnabled = true ;
299-
300319 /**
301320 * The horizontal scroll position of this Camera.
302321 *
@@ -595,6 +614,17 @@ var Camera = new Class({
595614 * @since 3.0.0
596615 */
597616 this . _follow = null ;
617+
618+ /**
619+ * Does this Camera have a custom viewport?
620+ *
621+ * @name Phaser.Cameras.Scene2D.Camera#_customViewport
622+ * @type {boolean }
623+ * @private
624+ * @default false
625+ * @since 3.12.0
626+ */
627+ this . _customViewport = false ;
598628 } ,
599629
600630 /**
@@ -1595,6 +1625,7 @@ var Camera = new Class({
15951625
15961626 /**
15971627 * Sets the Scene the Camera is bound to.
1628+ *
15981629 * Also populates the `resolution` property and updates the internal size values.
15991630 *
16001631 * @method Phaser.Cameras.Scene2D.Camera#setScene
@@ -1608,7 +1639,10 @@ var Camera = new Class({
16081639 {
16091640 this . scene = scene ;
16101641
1611- var res = scene . sys . game . config . resolution ;
1642+ this . config = scene . sys . game . config ;
1643+ this . sceneManager = scene . sys . game . scene ;
1644+
1645+ var res = this . config . resolution ;
16121646
16131647 this . resolution = res ;
16141648
@@ -1903,6 +1937,49 @@ var Camera = new Class({
19031937 }
19041938 } ,
19051939
1940+ /**
1941+ * Internal method called automatically when the viewport changes.
1942+ *
1943+ * @method Phaser.Cameras.Scene2D.Camera#updateSystem
1944+ * @protected
1945+ * @since 3.12.0
1946+ */
1947+ updateSystem : function ( )
1948+ {
1949+ var custom = false ;
1950+
1951+ if ( this . _x !== 0 || this . _y !== 0 )
1952+ {
1953+ custom = true ;
1954+ }
1955+ else
1956+ {
1957+ var gameWidth = this . config . width ;
1958+ var gameHeight = this . config . height ;
1959+
1960+ if ( gameWidth !== this . _width || gameHeight !== this . _height )
1961+ {
1962+ custom = true ;
1963+ }
1964+ }
1965+
1966+ var sceneManager = this . sceneManager ;
1967+
1968+ if ( custom && ! this . _customViewport )
1969+ {
1970+ // We need a custom viewport for this Camera
1971+ sceneManager . customViewports ++ ;
1972+ }
1973+ else if ( ! custom && this . _customViewport )
1974+ {
1975+ // We're turning off a custom viewport for this Camera
1976+ sceneManager . customViewports -- ;
1977+ }
1978+
1979+ this . dirty = true ;
1980+ this . _customViewport = custom ;
1981+ } ,
1982+
19061983 /**
19071984 * This event is fired when a camera is destroyed by the Camera Manager.
19081985 *
@@ -1932,10 +2009,19 @@ var Camera = new Class({
19322009
19332010 this . culledObjects = [ ] ;
19342011
2012+ if ( this . _customViewport )
2013+ {
2014+ // We're turning off a custom viewport for this Camera
2015+ this . sceneManager . customViewports -- ;
2016+ }
2017+
19352018 this . _follow = null ;
19362019 this . _bounds = null ;
1937- this . scene = null ;
19382020 this . deadzone = null ;
2021+
2022+ this . scene = null ;
2023+ this . config = null ;
2024+ this . sceneManager = null ;
19392025 } ,
19402026
19412027 /**
@@ -1958,7 +2044,7 @@ var Camera = new Class({
19582044 {
19592045 this . _x = value ;
19602046 this . _cx = value * this . resolution ;
1961- this . dirty = true ;
2047+ this . updateSystem ( ) ;
19622048 }
19632049
19642050 } ,
@@ -1983,7 +2069,7 @@ var Camera = new Class({
19832069 {
19842070 this . _y = value ;
19852071 this . _cy = value * this . resolution ;
1986- this . dirty = true ;
2072+ this . updateSystem ( ) ;
19872073 }
19882074
19892075 } ,
@@ -2009,7 +2095,7 @@ var Camera = new Class({
20092095 {
20102096 this . _width = value ;
20112097 this . _cw = value * this . resolution ;
2012- this . dirty = true ;
2098+ this . updateSystem ( ) ;
20132099 }
20142100
20152101 } ,
@@ -2035,7 +2121,7 @@ var Camera = new Class({
20352121 {
20362122 this . _height = value ;
20372123 this . _ch = value * this . resolution ;
2038- this . dirty = true ;
2124+ this . updateSystem ( ) ;
20392125 }
20402126
20412127 } ,
0 commit comments