new CameraManager(scene)
Parameters:
| Name | Type | Description |
|---|---|---|
scene |
Phaser.Scene | The Scene that owns the Camera Manager plugin. |
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 15)
Members
-
cameras :Array.<Phaser.Cameras.Scene2D.Camera>
-
An Array of the Camera objects being managed by this Camera Manager. The Cameras are updated and rendered in the same order in which they appear in this array. Do not directly add or remove entries to this array. However, you can move the contents around the array should you wish to adjust the display order.
Type:
- Array.<Phaser.Cameras.Scene2D.Camera>
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 89)
-
default :Phaser.Cameras.Scene2D.Camera
-
A default un-transformed Camera that doesn't exist on the camera list and doesn't count towards the total number of cameras being managed. It exists for other systems, as well as your own code, should they require a basic un-transformed camera instance from which to calculate a view matrix.
Type:
- Since: 3.17.0
- Source: src/cameras/2d/CameraManager.js (Line 118)
-
main :Phaser.Cameras.Scene2D.Camera
-
A handy reference to the 'main' camera. By default this is the first Camera the Camera Manager creates. You can also set it directly, or use the
makeMainargument in theaddandaddExistingmethods. It allows you to access it from your game:var cam = this.cameras.main;Also see the properties
camera1,camera2and so on.Type:
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 101)
-
roundPixels :boolean
-
All Cameras created by, or added to, this Camera Manager, will have their
roundPixelsproperty set to match this value. By default it is set to match the value set in the game configuration, but can be changed at any point. Equally, individual cameras can also be changed as needed.Type:
- boolean
- Since: 3.11.0
- Source: src/cameras/2d/CameraManager.js (Line 77)
-
scene :Phaser.Scene
-
The Scene that owns the Camera Manager plugin.
Type:
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 59)
-
systems :Phaser.Scenes.Systems
-
A reference to the Scene.Systems handler for the Scene that owns the Camera Manager.
Type:
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 68)
Methods
-
add( [x] [, y] [, width] [, height] [, makeMain] [, name])
-
Adds a new Camera into the Camera Manager. The Camera Manager can support up to 31 different Cameras.
Each Camera has its own viewport, which controls the size of the Camera and its position within the canvas.
Use the
Camera.scrollXandCamera.scrollYproperties to change where the Camera is looking, or the Camera methods such ascenterOn. Cameras also have built in special effects, such as fade, flash, shake, pan and zoom.By default Cameras are transparent and will render anything that they can see based on their
scrollXandscrollYvalues. Game Objects can be set to be ignored by a Camera by using theCamera.ignoremethod.The Camera will have its
roundPixelsproperty set to whateverCameraManager.roundPixelsis. You can change it after creation if required.See the Camera class documentation for more details.
Parameters:
Name Type Argument Default Description xnumber <optional>
0 The horizontal position of the Camera viewport.
ynumber <optional>
0 The vertical position of the Camera viewport.
widthnumber <optional>
The width of the Camera viewport. If not given it'll be the game config size.
heightnumber <optional>
The height of the Camera viewport. If not given it'll be the game config size.
makeMainboolean <optional>
false Set this Camera as being the 'main' camera. This just makes the property
maina reference to it.namestring <optional>
'' The name of the Camera.
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 205)
Returns:
The newly created Camera.
-
addExisting(camera [, makeMain])
-
Adds an existing Camera into the Camera Manager.
The Camera should either be a
Phaser.Cameras.Scene2D.Camerainstance, or a class that extends from it.The Camera will have its
roundPixelsproperty set to whateverCameraManager.roundPixelsis. You can change it after addition if required.The Camera will be assigned an ID, which is used for Game Object exclusion and then added to the manager. As long as it doesn't already exist in the manager it will be added then returned.
If this method returns
nullthen the Camera already exists in this Camera Manager.Parameters:
Name Type Argument Default Description cameraPhaser.Cameras.Scene2D.Camera The Camera to be added to the Camera Manager.
makeMainboolean <optional>
false Set this Camera as being the 'main' camera. This just makes the property
maina reference to it.- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 261)
Returns:
The Camera that was added to the Camera Manager, or
nullif it couldn't be added. -
fromJSON(config)
-
Populates this Camera Manager based on the given configuration object, or an array of config objects.
See the
Phaser.Types.Cameras.Scene2D.CameraConfigdocumentation for details of the object structure.Parameters:
Name Type Description configPhaser.Types.Cameras.Scene2D.CameraConfig | Array.<Phaser.Types.Cameras.Scene2D.CameraConfig> A Camera configuration object, or an array of them, to be added to this Camera Manager.
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 388)
Returns:
This Camera Manager instance.
-
getCamera(name)
-
Gets a Camera based on its name.
Camera names are optional and don't have to be set, so this method is only of any use if you have given your Cameras unique names.
Parameters:
Name Type Description namestring The name of the Camera.
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 457)
Returns:
The first Camera with a name matching the given string, otherwise
null. -
getCamerasBelowPointer(pointer)
-
Returns an array of all cameras below the given Pointer.
The first camera in the array is the top-most camera in the camera list.
Parameters:
Name Type Description pointerPhaser.Input.Pointer The Pointer to check against.
- Since: 3.10.0
- Source: src/cameras/2d/CameraManager.js (Line 485)
Returns:
An array of cameras below the Pointer.
- Type
- Array.<Phaser.Cameras.Scene2D.Camera>
-
getTotal( [isVisible])
-
Gets the total number of Cameras in this Camera Manager.
If the optional
isVisibleargument is set it will only count Cameras that are currently visible.Parameters:
Name Type Argument Default Description isVisibleboolean <optional>
false Set the
trueto only include visible Cameras in the total.- Since: 3.11.0
- Source: src/cameras/2d/CameraManager.js (Line 355)
Returns:
The total number of Cameras in this Camera Manager.
- Type
- number
-
getVisibleChildren(children, camera)
-
Takes an array of Game Objects and a Camera and returns a new array containing only those Game Objects that pass the
willRendertest against the given Camera.Parameters:
Name Type Description childrenArray.<Phaser.GameObjects.GameObject> An array of Game Objects to be checked against the camera.
cameraPhaser.Cameras.Scene2D.Camera The camera to filte the Game Objects against.
- Since: 3.50.0
- Source: src/cameras/2d/CameraManager.js (Line 608)
Returns:
A filtered list of only Game Objects within the Scene that will render against the given Camera.
- Type
- Array.<Phaser.GameObjects.GameObject>
-
onResize(gameSize, baseSize)
-
The event handler that manages the
resizeevent dispatched by the Scale Manager.Parameters:
Name Type Description gameSizePhaser.Structs.Size The default Game Size object. This is the un-modified game dimensions.
baseSizePhaser.Structs.Size The base Size object. The game dimensions. The canvas width / height values match this.
- Since: 3.18.0
- Source: src/cameras/2d/CameraManager.js (Line 681)
-
remove(camera [, runDestroy])
-
Removes the given Camera, or an array of Cameras, from this Camera Manager.
If found in the Camera Manager it will be immediately removed from the local cameras array. If also currently the 'main' camera, 'main' will be reset to be camera 0.
The removed Cameras are automatically destroyed if the
runDestroyargument istrue, which is the default. If you wish to re-use the cameras then set this tofalse, but know that they will retain their references and internal data until destroyed or re-added to a Camera Manager.Parameters:
Name Type Argument Default Description cameraPhaser.Cameras.Scene2D.Camera | Array.<Phaser.Cameras.Scene2D.Camera> The Camera, or an array of Cameras, to be removed from this Camera Manager.
runDestroyboolean <optional>
true Automatically call
Camera.destroyon each Camera removed from this Camera Manager.- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 520)
Returns:
The total number of Cameras removed.
- Type
- number
-
<protected> render(renderer, children)
-
The internal render method. This is called automatically by the Scene and should not be invoked directly.
It will iterate through all local cameras and render them in turn, as long as they're visible and have an alpha level > 0.
Parameters:
Name Type Description rendererPhaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer The Renderer that will render the children to this camera.
childrenPhaser.GameObjects.DisplayList The Display List for the Scene.
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 575)
-
resetAll()
-
Resets this Camera Manager.
This will iterate through all current Cameras, destroying them all, then it will reset the cameras array, reset the ID counter and create 1 new single camera using the default values.
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 638)
Returns:
The freshly created main Camera.
-
resize(width, height)
-
Resizes all cameras to the given dimensions.
Parameters:
Name Type Description widthnumber The new width of the camera.
heightnumber The new height of the camera.
- Since: 3.2.0
- Source: src/cameras/2d/CameraManager.js (Line 706)
-
<protected> update(time, delta)
-
The main update loop. Called automatically when the Scene steps.
Parameters:
Name Type Description timenumber The current timestamp as generated by the Request Animation Frame or SetTimeout.
deltanumber The delta time, in ms, elapsed since the last frame.
- Since: 3.0.0
- Source: src/cameras/2d/CameraManager.js (Line 663)
