Class: BaseCamera

Phaser.Cameras.Scene2D. BaseCamera

A Base Camera class.

The Camera is the way in which all games are rendered in Phaser. They provide a view into your game world,
and can be positioned, rotated, zoomed and scrolled accordingly.

A Camera consists of two elements: The viewport and the scroll values.

The viewport is the physical position and size of the Camera within your game. Cameras, by default, are
created the same size as your game, but their position and size can be set to anything. This means if you
wanted to create a camera that was 320x200 in size, positioned in the bottom-right corner of your game,
you'd adjust the viewport to do that (using methods like setViewport and setSize).

If you wish to change where the Camera is looking in your game, then you scroll it. You can do this
via the properties scrollX and scrollY or the method setScroll. Scrolling has no impact on the
viewport, and changing the viewport has no impact on the scrolling.

By default a Camera will render all Game Objects it can see. You can change this using the ignore method,
allowing you to filter Game Objects out on a per-Camera basis.

The Base Camera is extended by the Camera class, which adds in special effects including Fade,
Flash and Camera Shake, as well as the ability to follow Game Objects.

The Base Camera was introduced in Phaser 3.12. It was split off from the Camera class, to allow
you to isolate special effects as needed. Therefore the 'since' values for properties of this class relate
to when they were added to the Camera class.


new BaseCamera(x, y, width, height)

Parameters:
Name Type Description
x number

The x position of the Camera, relative to the top-left of the game canvas.

y number

The y position of the Camera, relative to the top-left of the game canvas.

width number

The width of the Camera, in pixels.

height number

The height of the Camera, in pixels.

Since: 3.12.0
Source: src/cameras/2d/BaseCamera.js (Line 41)

Extends

Members


alpha :number

The Camera alpha value. Setting this property impacts every single object that this Camera
renders. You can either set the property directly, i.e. via a Tween, to fade a Camera in or out,
or via the chainable setAlpha method instead.

Type:
  • number
Since: 3.11.0
Overrides:
Default Value:
  • 1
Source: src/cameras/2d/BaseCamera.js (Line 424)

alphaBottomLeft :number

The alpha value starting from the bottom-left of the Game Object.
This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 227)

alphaBottomRight :number

The alpha value starting from the bottom-right of the Game Object.
This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 257)

alphaTopLeft :number

The alpha value starting from the top-left of the Game Object.
This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 167)

alphaTopRight :number

The alpha value starting from the top-right of the Game Object.
This value is interpolated from the corner to the center of the Game Object.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 197)

backgroundColor :Phaser.Display.Color

The background color of this Camera. Only used if transparent is false.

Type:
Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 415)

<readonly> centerX :number

The x position of the center of the Camera's viewport, relative to the top-left of the game canvas.

Type:
  • number
Since: 3.10.0
Source: src/cameras/2d/BaseCamera.js (Line 1702)

<readonly> centerY :number

The y position of the center of the Camera's viewport, relative to the top-left of the game canvas.

Type:
  • number
Since: 3.10.0
Source: src/cameras/2d/BaseCamera.js (Line 1719)

<readonly> config :object

A reference to the Game Config.

Type:
  • object
Since: 3.12.0
Source: src/cameras/2d/BaseCamera.js (Line 121)

dirty :boolean

Is this Camera dirty?

A dirty Camera has had either its viewport size, bounds, scroll, rotation or zoom levels changed since the last frame.

This flag is cleared during the postRenderCamera method of the renderer.

Type:
  • boolean
Since: 3.11.0
Default Value:
  • true
Source: src/cameras/2d/BaseCamera.js (Line 209)

disableCull :boolean

Should the camera cull Game Objects before checking them for input hit tests?
In some special cases it may be beneficial to disable this.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/cameras/2d/BaseCamera.js (Line 435)

<readonly> displayHeight :number

The displayed height of the camera viewport, factoring in the camera zoom level.

If a camera has a viewport height of 600 and a zoom of 0.5 then its display height
would be 1200, as it's displaying twice as many pixels as zoom level 1.

Equally, a camera with a height of 600 and zoom of 2 would have a display height
of 300 pixels.

Type:
  • number
Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 1759)

<readonly> displayWidth :number

The displayed width of the camera viewport, factoring in the camera zoom level.

If a camera has a viewport width of 800 and a zoom of 0.5 then its display width
would be 1600, as it's displaying twice as many pixels as zoom level 1.

Equally, a camera with a width of 800 and zoom of 2 would have a display width
of 400 pixels.

Type:
  • number
Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 1736)

height :number

The height of the Camera viewport, in pixels.

The viewport is the area into which the Camera renders. Setting the viewport does
not restrict where the Camera can scroll to.

Type:
  • number
Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1555)

<readonly> id :integer

The Camera ID. Assigned by the Camera Manager and used to handle camera exclusion.
This value is a bitmask.

Type:
  • integer
Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 131)

<readonly> midPoint :Phaser.Math.Vector2

The mid-point of the Camera in 'world' coordinates.

Use it to obtain exactly where in the world the center of the camera is currently looking.

This value is updated in the preRender method, after the scroll values and follower
have been processed.

Type:
Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 457)

name :string

The name of the Camera. This is left empty for your own use.

Type:
  • string
Since: 3.0.0
Default Value:
  • ''
Source: src/cameras/2d/BaseCamera.js (Line 142)

originX :number

The horizontal origin of rotation for this Camera.

By default the camera rotates around the center of the viewport.

Changing the origin allows you to adjust the point in the viewport from which rotation happens.
A value of 0 would rotate from the top-left of the viewport. A value of 1 from the bottom right.

See setOrigin to set both origins in a single, chainable call.

Type:
  • number
Since: 3.11.0
Default Value:
  • 0.5
Source: src/cameras/2d/BaseCamera.js (Line 472)

originY :number

The vertical origin of rotation for this Camera.

By default the camera rotates around the center of the viewport.

Changing the origin allows you to adjust the point in the viewport from which rotation happens.
A value of 0 would rotate from the top-left of the viewport. A value of 1 from the bottom right.

See setOrigin to set both origins in a single, chainable call.

Type:
  • number
Since: 3.11.0
Default Value:
  • 0.5
Source: src/cameras/2d/BaseCamera.js (Line 489)

<readonly> resolution :number

The resolution of the Game, used in most Camera calculations.

Type:
  • number
Since: 3.12.0
Source: src/cameras/2d/BaseCamera.js (Line 152)

roundPixels :boolean

Should this camera round its pixel values to integers?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/cameras/2d/BaseCamera.js (Line 162)

scene :Phaser.Scene

A reference to the Scene this camera belongs to.

Type:
Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 103)

sceneManager :Phaser.Scenes.SceneManager

A reference to the Game Scene Manager.

Type:
Since: 3.12.0
Source: src/cameras/2d/BaseCamera.js (Line 112)

scrollX :number

The horizontal scroll position of this Camera.

Change this value to cause the Camera to scroll around your Scene.

Alternatively, setting the Camera to follow a Game Object, via the startFollow method,
will automatically adjust the Camera scroll values accordingly.

You can set the bounds within which the Camera can scroll via the setBounds method.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/cameras/2d/BaseCamera.js (Line 1581)

scrollY :number

The vertical scroll position of this Camera.

Change this value to cause the Camera to scroll around your Scene.

Alternatively, setting the Camera to follow a Game Object, via the startFollow method,
will automatically adjust the Camera scroll values accordingly.

You can set the bounds within which the Camera can scroll via the setBounds method.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/cameras/2d/BaseCamera.js (Line 1611)

transparent :boolean

Does this Camera have a transparent background?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • true
Source: src/cameras/2d/BaseCamera.js (Line 405)

useBounds :boolean

Is this Camera using a bounds to restrict scrolling movement?

Set this property along with the bounds via Camera.setBounds.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/cameras/2d/BaseCamera.js (Line 184)

visible :boolean

Is this Camera visible or not?

A visible camera will render and perform input tests.
An invisible camera will not render anything and will skip input tests.

Type:
  • boolean
Since: 3.10.0
Overrides:
Default Value:
  • true
Source: src/cameras/2d/BaseCamera.js (Line 172)

width :number

The width of the Camera viewport, in pixels.

The viewport is the area into which the Camera renders. Setting the viewport does
not restrict where the Camera can scroll to.

Type:
  • number
Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1529)

<readonly> worldView :Phaser.Geom.Rectangle

The World View is a Rectangle that defines the area of the 'world' the Camera is currently looking at.
This factors in the Camera viewport size, zoom and scroll position and is updated in the Camera preRender step.
If you have enabled Camera bounds the worldview will be clamped to those bounds accordingly.
You can use it for culling or intersection checks.

Type:
Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 196)

x :number

The x position of the Camera viewport, relative to the top-left of the game canvas.
The viewport is the area into which the camera renders.
To adjust the position the camera is looking at in the game world, see the scrollX value.

Type:
  • number
Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1479)

y :number

The y position of the Camera viewport, relative to the top-left of the game canvas.
The viewport is the area into which the camera renders.
To adjust the position the camera is looking at in the game world, see the scrollY value.

Type:
  • number
Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1504)

zoom :number

The Camera zoom value. Change this value to zoom in, or out of, a Scene.

A value of 0.5 would zoom the Camera out, so you can now see twice as much
of the Scene as before. A value of 2 would zoom the Camera in, so every pixel
now takes up 2 pixels when rendered.

Set to 1 to return to the default zoom level.

Be careful to never set this value to zero.

Type:
  • number
Since: 3.0.0
Default Value:
  • 1
Source: src/cameras/2d/BaseCamera.js (Line 1641)

Methods


addListener(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 111)
Returns:

this.

Type
Phaser.Events.EventEmitter

centerOn(x, y)

Moves the Camera so that it is centered on the given coordinates, bounds allowing.

Parameters:
Name Type Description
x number

The horizontal coordinate to center on.

y number

The vertical coordinate to center on.

Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 592)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

centerToBounds()

Moves the Camera so that it is looking at the center of the Camera Bounds, if enabled.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 622)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

centerToSize()

Moves the Camera so that it is re-centered based on its viewport size.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 647)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

clampX(x)

Takes an x value and checks it's within the range of the Camera bounds, adjusting if required.
Do not call this method if you are not using camera bounds.

Parameters:
Name Type Description
x number

The value to horizontally scroll clamp.

Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 920)
Returns:

The adjusted value to use as scrollX.

Type
number

clampY(y)

Takes a y value and checks it's within the range of the Camera bounds, adjusting if required.
Do not call this method if you are not using camera bounds.

Parameters:
Name Type Description
y number

The value to vertically scroll clamp.

Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 952)
Returns:

The adjusted value to use as scrollY.

Type
number

clearAlpha()

Clears all alpha values associated with this Game Object.

Immediately sets the alpha levels back to 1 (fully opaque).

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Alpha.js (Line 77)
Returns:

This Game Object instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

cull(renderableObjects)

Takes an array of Game Objects and returns a new array featuring only those objects
visible by this camera.

Parameters:
Name Type Description
renderableObjects Array.<Phaser.GameObjects.GameObject>

An array of Game Objects to cull.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 663)
Returns:

An array of Game Objects visible to this Camera.

Type
Array.<Phaser.GameObjects.GameObject>

destroy()

Destroys this Camera instance and its internal properties and references.
Once destroyed you cannot use this Camera again, even if re-added to a Camera Manager.

This method is called automatically by CameraManager.remove if that methods runDestroy argument is true, which is the default.

Unless you have a specific reason otherwise, always use CameraManager.remove and allow it to handle the camera destruction,
rather than calling this method directly.

Since: 3.0.0
Overrides:
Source: src/cameras/2d/BaseCamera.js (Line 1443)
Fires:

emit(event [, args])

Calls each of the listeners registered for a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

args * <optional>
<repeatable>

Additional arguments that will be passed to the event handler.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 86)
Returns:

true if the event had listeners, else false.

Type
boolean

eventNames()

Return an array listing the events for which the emitter has registered listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 55)
Returns:
Type
array

getScroll(x, y [, out])

Calculates what the Camera.scrollX and scrollY values would need to be in order to move
the Camera so it is centered on the given x and y coordinates, without actually moving
the Camera there. The results are clamped based on the Camera bounds, if set.

Parameters:
Name Type Argument Description
x number

The horizontal coordinate to center on.

y number

The vertical coordinate to center on.

out Phaser.Math.Vector2 <optional>

A Vec2 to store the values in. If not given a new Vec2 is created.

Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 559)
Returns:

The scroll coordinates stored in the x abd y properties.

Type
Phaser.Math.Vector2

getWorldPoint(x, y [, output])

Converts the given x and y coordinates into World space, based on this Cameras transform.
You can optionally provide a Vector2, or similar object, to store the results in.

Parameters:
Name Type Argument Description
x number

The x position to convert to world space.

y number

The y position to convert to world space.

output object | Phaser.Math.Vector2 <optional>

An optional object to store the results in. If not provided a new Vector2 will be created.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 743)
Returns:

An object holding the converted values in its x and y properties.

Type
Phaser.Math.Vector2

ignore(entries)

Given a Game Object, or an array of Game Objects, it will update all of their camera filter settings
so that they are ignored by this Camera. This means they will not be rendered by this Camera.

Parameters:
Name Type Description
entries Phaser.GameObjects.GameObject | Array.<Phaser.GameObjects.GameObject> | Phaser.GameObjects.Group

The Game Object, or array of Game Objects, to be ignored by this Camera.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 811)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

listenerCount(event)

Return the number of listeners listening to a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 75)
Returns:

The number of listeners.

Type
number

listeners(event)

Return the listeners registered for a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 64)
Returns:

The registered listeners.

Type
array

off(event, fn, context, once)

Remove the listeners of a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

fn function

Only remove the listeners that match this function.

context *

Only remove the listeners that have this context.

once boolean

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 151)
Returns:

this.

Type
Phaser.Events.EventEmitter

on(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 98)
Returns:

this.

Type
Phaser.Events.EventEmitter

once(event, fn [, context])

Add a one-time listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 124)
Returns:

this.

Type
Phaser.Events.EventEmitter

<protected> preRender(baseScale, resolution)

Internal preRender step.

Parameters:
Name Type Description
baseScale number

The base scale, as set in the Camera Manager.

resolution number

The game resolution.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 852)

removeAllListeners( [event])

Remove all listeners, or those of the specified event.

Parameters:
Name Type Argument Description
event string | symbol <optional>

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 165)
Returns:

this.

Type
Phaser.Events.EventEmitter

removeBounds()

If this Camera has previously had movement bounds set on it, this will remove them.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 989)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

removeListener(event, fn, context, once)

Remove the listeners of a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

fn function

Only remove the listeners that match this function.

context *

Only remove the listeners that have this context.

once boolean

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 137)
Returns:

this.

Type
Phaser.Events.EventEmitter

setAlpha( [value])

Set the Alpha level of this Camera. The alpha controls the opacity of the Camera as it renders.
Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque.

Parameters:
Name Type Argument Default Description
value number <optional>
1

The Camera alpha value.

Since: 3.11.0
Overrides:
Source: src/cameras/2d/BaseCamera.js (Line 518)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setAngle( [value])

Set the rotation of this Camera. This causes everything it renders to appear rotated.

Rotating a camera does not rotate the viewport itself, it is applied during rendering.

Parameters:
Name Type Argument Default Description
value number <optional>
0

The cameras angle of rotation, given in degrees.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1008)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setBackgroundColor( [color])

Sets the background color for this Camera.

By default a Camera has a transparent background but it can be given a solid color, with any level
of transparency, via this method.

The color value can be specified using CSS color notation, hex or numbers.

Parameters:
Name Type Argument Default Description
color string | number | InputColorObject <optional>
'rgba(0,0,0,0)'

The color value. In CSS, hex or numeric color notation.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1029)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setBounds(x, y, width, height [, centerOn])

Set the bounds of the Camera. The bounds are an axis-aligned rectangle.

The Camera bounds controls where the Camera can scroll to, stopping it from scrolling off the
edges and into blank space. It does not limit the placement of Game Objects, or where
the Camera viewport can be positioned.

Temporarily disable the bounds by changing the boolean Camera.useBounds.

Clear the bounds entirely by calling Camera.removeBounds.

If you set bounds that are smaller than the viewport it will stop the Camera from being
able to scroll. The bounds can be positioned where-ever you wish. By default they are from
0x0 to the canvas width x height. This means that the coordinate 0x0 is the top left of
the Camera bounds. However, you can position them anywhere. So if you wanted a game world
that was 2048x2048 in size, with 0x0 being the center of it, you can set the bounds x/y
to be -1024, -1024, with a width and height of 2048. Depending on your game you may find
it easier for 0x0 to be the top-left of the bounds, or you may wish 0x0 to be the middle.

Parameters:
Name Type Argument Description
x integer

The top-left x coordinate of the bounds.

y integer

The top-left y coordinate of the bounds.

width integer

The width of the bounds, in pixels.

height integer

The height of the bounds, in pixels.

centerOn boolean <optional>

If true the Camera will automatically be centered on the new bounds.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1055)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setName( [value])

Sets the name of this Camera.
This value is for your own use and isn't used internally.

Parameters:
Name Type Argument Default Description
value string <optional>
''

The name of the Camera.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1105)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setOrigin( [x] [, y])

Sets the rotation origin of this Camera.

The values are given in the range 0 to 1 and are only used when calculating Camera rotation.

By default the camera rotates around the center of the viewport.

Changing the origin allows you to adjust the point in the viewport from which rotation happens.
A value of 0 would rotate from the top-left of the viewport. A value of 1 from the bottom right.

Parameters:
Name Type Argument Default Description
x number <optional>
0.5

The horizontal origin value.

y number <optional>
x

The vertical origin value. If not defined it will be set to the value of x.

Since: 3.11.0
Source: src/cameras/2d/BaseCamera.js (Line 530)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setPosition(x [, y])

Set the position of the Camera viewport within the game.

This does not change where the camera is 'looking'. See setScroll to control that.

Parameters:
Name Type Argument Default Description
x number

The top-left x coordinate of the Camera viewport.

y number <optional>
x

The top-left y coordinate of the Camera viewport.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1125)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setRotation( [value])

Set the rotation of this Camera. This causes everything it renders to appear rotated.

Rotating a camera does not rotate the viewport itself, it is applied during rendering.

Parameters:
Name Type Argument Default Description
value number <optional>
0

The rotation of the Camera, in radians.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1148)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setRoundPixels(value)

Should the Camera round pixel values to whole integers when rendering Game Objects?

In some types of game, especially with pixel art, this is required to prevent sub-pixel aliasing.

Parameters:
Name Type Description
value boolean

true to round Camera pixels, false to not.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1169)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setScene(scene)

Sets the Scene the Camera is bound to.

Also populates the resolution property and updates the internal size values.

Parameters:
Name Type Description
scene Phaser.Scene

The Scene the camera is bound to.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1188)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setScroll(x [, y])

Set the position of where the Camera is looking within the game.
You can also modify the properties Camera.scrollX and Camera.scrollY directly.
Use this method, or the scroll properties, to move your camera around the game world.

This does not change where the camera viewport is placed. See setPosition to control that.

Parameters:
Name Type Argument Default Description
x number

The x coordinate of the Camera in the game world.

y number <optional>
x

The y coordinate of the Camera in the game world.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1226)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setSize(width [, height])

Set the size of the Camera viewport.

By default a Camera is the same size as the game, but can be made smaller via this method,
allowing you to create mini-cam style effects by creating and positioning a smaller Camera
viewport within your game.

Parameters:
Name Type Argument Default Description
width integer

The width of the Camera viewport.

height integer <optional>
width

The height of the Camera viewport.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1251)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setViewport(x, y, width [, height])

This method sets the position and size of the Camera viewport in a single call.

If you're trying to change where the Camera is looking at in your game, then see
the method Camera.setScroll instead. This method is for changing the viewport
itself, not what the camera can see.

By default a Camera is the same size as the game, but can be made smaller via this method,
allowing you to create mini-cam style effects by creating and positioning a smaller Camera
viewport within your game.

Parameters:
Name Type Argument Default Description
x number

The top-left x coordinate of the Camera viewport.

y number

The top-left y coordinate of the Camera viewport.

width integer

The width of the Camera viewport.

height integer <optional>
width

The height of the Camera viewport.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1276)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setVisible(value)

Sets the visibility of this Camera.

An invisible Camera will skip rendering and input tests of everything it can see.

Parameters:
Name Type Description
value boolean

The visible state of the Camera.

Since: 3.10.0
Overrides:
Source: src/cameras/2d/BaseCamera.js (Line 1338)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

setZoom( [value])

Set the zoom value of the Camera.

Changing to a smaller value, such as 0.5, will cause the camera to 'zoom out'.
Changing to a larger value, such as 2, will cause the camera to 'zoom in'.

A value of 1 means 'no zoom' and is the default.

Changing the zoom does not impact the Camera viewport in any way, it is only applied during rendering.

Parameters:
Name Type Argument Default Description
value number <optional>
1

The zoom value of the Camera. The minimum it can be is 0.001.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1307)
Returns:

This Camera instance.

Type
Phaser.Cameras.Scene2D.BaseCamera

shutdown()

Removes all listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 31)

toJSON()

Returns an Object suitable for JSON storage containing all of the Camera viewport and rendering properties.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1351)
Returns:

A well-formed object suitable for conversion to JSON.

Type
JSONCamera

<protected> update(time, delta)

Internal method called automatically by the Camera Manager.

Parameters:
Name Type Description
time integer

The current timestamp as generated by the Request Animation Frame or SetTimeout.

delta number

The delta time, in ms, elapsed since the last frame.

Since: 3.0.0
Source: src/cameras/2d/BaseCamera.js (Line 1388)